<template>
  <div>
    <Modal
      :title="modalTitle"
      :mask-closable="false"
      :closable="isDisableEdit"
      class="formTop"
      v-model="showOrderDiscountModal"
      width="70%"
    >
      <Form
        ref="orderDiscountFormItem"
        :model="formItem"
        :label-width="90"
        :rules="formRules"
        class="form-box"
      >
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动基础信息</span>
        <Row :gutter="20">
          <Col span="9">
            <FormItem label="活动名称" prop="activityName">
              <Input
                v-model="formItem.activityName"
                :disabled="isDisableEdit"
                placeholder="请输入活动名称"
              />
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动对象" style="margin-bottom: 14px;" prop="activityMatchUserType">
              <RadioGroup v-model="formItem.activityMatchUserType">
                <Radio label="0" :disabled="isDisableEdit" checked>全部顾客</Radio>
                <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">仅会员</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动渠道" style="margin-bottom: 14px;">
              <Checkbox
                v-model="formItem.activityChannelPosType"
                :disabled="true"
              >
                收银机
              </Checkbox>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="accountType == 'company'">
          <Col span="23">
            <FormItem label="活动门店" style="margin-bottom: 14px;width: 90%" prop="activeShopList">
                <div v-if="isDisableEdit">
                  <span
                  >
                    {{formItem.activeShopList.length == storeList.length ? '全部门店' : formItem.activeShopList.length + '家门店'}}
                  </span>
                </div>
                <div v-else>
                  <span
                    class="activity-shop-desc"
                    @click="activityShopChoice"
                    v-if="formItem.activeShopList.length != 0 && formItem.activeShopList.length == storeList.length"
                  >
                    请选择门店（已选全部门店）
                  </span>
                  <span
                    class="activity-shop-desc"
                    @click="activityShopChoice"
                    v-else
                  >
                    请选择门店（已选{{ formItem.activeShopList.length }}个）
                  </span>
                </div>
              <div
                class="activity-product-target-category-list"
                v-if="formItem.activeShopList.length && !isDisableEdit"
              >
                <div
                  class="activity-product-target-category-list-cell"
                  v-for="(item, index) in formItem.activeShopList"
                >
                  <span
                    class="activity-product-target-category-list-cell-text"
                  >
                    {{ item.storeName }}
                  </span>
                  <img
                    src="../../assets/images/delete.png"
                    alt=""
                    class="activity-product-target-category-list-cell-img"
                    @click="handleDeleteSelectedActivityShop(index)"
                  />
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动日期</span>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动日期" style="margin-bottom: 14px;" prop="activityDateType">
              <RadioGroup v-model="formItem.activityDateType">
                <Radio label="0" :disabled="isDisableEdit" checked>永久有效</Radio>
                <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">自定义日期</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.activityDateType == '1'">
          <Col span="9">
            <FormItem label="自定义日期" style="margin-bottom: 14px;" prop="activityDateRange">
              <div v-if="isDisableEdit">
                {{formItem.activityDateStart + ' — ' + formItem.activityDateEnd}}
              </div>
              <DatePicker
                v-else
                type="daterange"
                :options="optionTime"
                format="yyyy-MM-dd"
                @on-change="handleCustomDateChange"
                :value="formItem.activityDateRange"
                :editable="false"
                split-panels
                style="width: 300px"
              >
              </DatePicker>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="!isDisableEdit">
          <div class="more-settings" @click="handleUnfoldMoreSettings">
            <span v-if="formItem.isUnfoldMoreSettings" class="more-settings-text">收起更多设置</span>
            <span v-if="!formItem.isUnfoldMoreSettings" class="more-settings-text">展开更多设置</span>
            <img v-if="formItem.isUnfoldMoreSettings" class="more-settings-icon" src="../../assets/images/fold.png" alt="">
            <img v-if="!formItem.isUnfoldMoreSettings"  class="more-settings-icon" src="../../assets/images/unfold.png" alt="">
          </div>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings || isDisableEdit">
          <Col span="11">
            <FormItem label="不可用日期" style="margin-bottom: 14px;">
              <div v-if="isDisableEdit && (!formItem.invalidDateList || formItem.invalidDateList.length < 1)">
                -------
              </div>
              <div v-else>
                <div
                  class="disable-date-pickers"
                  v-for="(item, index) in formItem.invalidDateList"
                  :key="item.id"
                  :style="{ marginTop: ((index > 0 ? 1 : 0) * 15) + 'px' }"
                >
                  <DatePicker
                    type="daterange"
                    :disabled="isDisableEdit"
                    :options="optionTime"
                    format="yyyy-MM-dd"
                    @on-change="(value) => handleCustomDisableDateChange(value, index)"
                    :value="item.dateRange"
                    :editable="false"
                    split-panels
                    :style="{ width: '300px'}"
                  >
                  </DatePicker>
                  <Button
                    v-if="!isDisableEdit"
                    class="disable-date-picker-delete"
                    @click="handleDeleteDisableDatePicker(index)"
                  >
                    删除
                  </Button>
                </div>
                <div class="disable-date-add">
                  <span
                    class="disable-date-add-text"
                    v-if="formItem.invalidDateList.length < 51 && !isDisableEdit"
                    @click="handleAddDisableDateRange"
                  >
                    添加一个日期段
                  </span>
                  <span class="disable-date-add-tip">该促销活动在指定日期不生效</span>
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings || isDisableEdit">
          <Col span="13">
            <FormItem label="活动星期" style="margin-bottom: 14px;" prop="activityMatchDayOfWeek">
              <Checkbox
                v-if="!isDisableEdit"
                :indeterminate="activityDaysOfWeekIndeterminate"
                :value="checkActivityDaysOfWeekAll"
                @on-change="handleCheckActivityDaysOfWeekAll"
              >
                全选
              </Checkbox>
              <CheckboxGroup v-model="checkActivityDaysOfWeekAllGroup" @on-change="handleCheckActivityDaysOfWeekAllGroupChange">
                <Checkbox label="星期一" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期二" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期三" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期四" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期五" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期六" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期日" :disabled="isDisableEdit"></Checkbox>
              </CheckboxGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings">
          <Col span="11">
            <FormItem label="活动时间" style="margin-bottom: 14px;">
              <TimePicker
                type="time"
                format="HH:mm"
                @on-change="handleActivityTimeStartChange"
                :value="formItem.activityTimeStart"
                :editable="false"
                split-panels
                style="width: 135px"
              >
              </TimePicker>
              <span class="activity-time-separation-text">至</span>
              <TimePicker
                type="time"
                format="HH:mm"
                @on-change="handleActivityTimeEndChange"
                :value="formItem.activityTimeEnd"
                :editable="false"
                split-panels
                style="width: 135px"
              >
              </TimePicker>
            </FormItem>
          </Col>
        </Row>
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动规则</span>
        <Row :gutter="20">
          <Col span="9">
            <FormItem label="整单折扣率" prop="activityRuleRate">
              <Input
                v-model="formItem.activityRuleRate"
                :disabled="isDisableEdit"
                :maxlength="2"
                style="width: 160px"
                placeholder="打8折，请输入80"
              >
                <span slot="append" style="color: #ffffff">%</span>
              </Input>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="21">
            <FormItem label="适用商品" style="margin-bottom: 14px;" prop="activityProductTargetFlag">
              <RadioGroup v-model="formItem.activityProductConditionType">
                <Radio label="0" :disabled="isDisableEdit" checked>全部商品</Radio>
                <Radio v-if="accountType == 'store'" label="1" :disabled="isDisableEdit" style="margin-left: 10px;">部分可用</Radio>
              </RadioGroup>
              <div
                class="activity-product-target-category"
                v-if="formItem.activityProductConditionType == '1'"
              >
                <div
                  class="activity-product-target-category-text"
                >
                  <span class="activity-product-target-category-text-title">指定分类：</span>
                  <span
                    v-if="isDisableEdit"
                    style="margin-right: 10px;"
                  >
                    已选{{ formItem.activityProductTypes.length }}个
                  </span>
                  <span
                    v-else
                    class="activity-product-target-category-text-add"
                    @click="activityProductTargetCategoryChoice"
                  >
                    选择分类（已选{{ formItem.activityProductTypes.length }}个）
                  </span>
                  <span class="activity-product-target-category-text-desc">
                    如选择指定类别，后期分类中增加商品自动适用当前活动
                  </span>
                </div>
                <div
                  class="activity-product-target-category-list"
                  v-if="formItem.activityProductTypes.length"
                >
                  <div
                    :class="`${isDisableEdit ? 'activity-product-target-category-list-cell disable' : 'activity-product-target-category-list-cell'}`"
                    v-for="(item, index) in formItem.activityProductTypes"
                  >
                    <span
                      :class="`${isDisableEdit ? 'activity-product-target-category-list-cell-text-disable' : 'activity-product-target-category-list-cell-text'}`"
                    >
                      {{ item.className }}
                    </span>
                    </span>
                    <img
                      v-if="!isDisableEdit"
                      src="../../assets/images/delete.png"
                      alt=""
                      class="activity-product-target-category-list-cell-img"
                      @click="deleteSelectedActivityProductTargetCategory(index)"
                    />
                  </div>
                </div>
              </div>
              <div
                class="activity-product-target"
                v-if="formItem.activityProductConditionType == '1'"
              >
                <div
                  class="activity-product-target-category-text"
                >
                  <span class="activity-product-target-category-text-title">指定商品：</span>
                  <span
                    v-if="isDisableEdit"
                  >
                    已选{{ formItem.activityProducts.length }}个
                  </span>
                  <span
                    v-else
                    class="activity-product-target-category-text-add"
                    @click="activityProductChoice(-1)"
                  >
                    选择商品（已选{{ formItem.activityProducts.length }}个）
                  </span>
                </div>
                <div
                  class="activity-product-target-category-list"
                  v-if="formItem.activityProducts.length"
                >
                  <div
                    :class="`${isDisableEdit ? 'activity-product-target-category-list-cell disable' : 'activity-product-target-category-list-cell'}`"
                    v-for="(item, index) in formItem.activityProducts"
                  >
                    <span
                      :class="`${isDisableEdit ? 'activity-product-target-category-list-cell-text-disable' : 'activity-product-target-category-list-cell-text'}`"
                    >
                      {{ item.productName }}
                    </span>
                    <span
                      v-if="isDisableEdit"
                      class="activity-product-target-category-list-cell-space"
                    >
                    </span>
                    <img
                      v-if="!isDisableEdit"
                      src="../../assets/images/delete.png"
                      alt=""
                      class="activity-product-target-category-list-cell-img"
                      @click="deleteSelectedActivityProduct(index)"
                    />
                  </div>
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="21">
            <FormItem label="活动说明">
              <Input
                v-model="formItem.activityDescription"
                :disabled="isDisableEdit"
                type="textarea"
                placeholder="请输入活动说明信息"
                :autosize="{minRows: 4,maxRows: 6}"
              />
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button v-if="!isDisableEdit" style="margin-left: 8px" @click="handleCancel">取消</Button>
        <Button v-if="!isDisableEdit" type="primary" @click="handleSubmit('orderDiscountFormItem')">保存</Button>
      </div>
    </Modal>
    <Modal
      :title="modalTitle"
      :mask-closable="false"
      :closable="isDisableEdit"
      class="formTop"
      v-model="showProductDiscountModal"
      width="70%"
    >
      <Form
        ref="productDiscountFormItem"
        :model="formItem"
        :label-width="90"
        :rules="formRules"
        class="form-box"
      >
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动基础信息</span>
        <Row :gutter="20">
          <Col span="9">
            <FormItem label="活动名称" prop="activityName">
              <Input
                v-model="formItem.activityName"
                :disabled="isDisableEdit"
                placeholder="请输入活动名称"
              />
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动对象" style="margin-bottom: 14px;" prop="activityMatchUserType">
              <RadioGroup v-model="formItem.activityMatchUserType">
                <Radio label="0" :disabled="isDisableEdit" checked>全部顾客</Radio>
                <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">仅会员</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动渠道" style="margin-bottom: 14px;">
              <Checkbox
                v-model="formItem.activityChannelPosType"
                :disabled="true"
              >
                收银机
              </Checkbox>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="accountType == 'company'">
          <Col span="23">
            <FormItem label="活动门店" style="margin-bottom: 14px;width: 90%" prop="activeShopList">
                <div v-if="isDisableEdit">
                  <span
                  >
                    {{formItem.activeShopList.length == storeList.length ? '全部门店' : formItem.activeShopList.length + '家门店'}}
                  </span>
                </div>
                <div v-else>
                  <span
                    class="activity-shop-desc"
                    @click="activityShopChoice"
                    v-if="formItem.activeShopList.length != 0 && formItem.activeShopList.length == storeList.length"
                  >
                    请选择门店（已选全部门店）
                  </span>
                  <span
                    class="activity-shop-desc"
                    @click="activityShopChoice"
                    v-else
                  >
                    请选择门店（已选{{ formItem.activeShopList.length }}个）
                  </span>
                </div>
              <div
                class="activity-product-target-category-list"
                v-if="formItem.activeShopList.length && !isDisableEdit"
              >
                <div
                  class="activity-product-target-category-list-cell"
                  v-for="(item, index) in formItem.activeShopList"
                >
                  <span
                    class="activity-product-target-category-list-cell-text"
                  >
                    {{ item.storeName }}
                  </span>
                  <img
                    src="../../assets/images/delete.png"
                    alt=""
                    class="activity-product-target-category-list-cell-img"
                    @click="handleDeleteSelectedActivityShop(index)"
                  />
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动日期</span>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动日期" style="margin-bottom: 14px;" prop="activityDateType">
              <RadioGroup v-model="formItem.activityDateType">
                <Radio label="0" :disabled="isDisableEdit" checked>永久有效</Radio>
                <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">自定义日期</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.activityDateType == '1'">
          <Col span="9">
            <FormItem label="自定义日期" style="margin-bottom: 14px;" prop="activityDateRange">
              <div v-if="isDisableEdit">
                {{formItem.activityDateStart + ' — ' + formItem.activityDateEnd}}
              </div>
              <DatePicker
                v-else
                type="daterange"
                :options="optionTime"
                format="yyyy-MM-dd"
                @on-change="handleCustomDateChange"
                :value="formItem.activityDateRange"
                :editable="false"
                split-panels
                style="width: 300px"
              >
              </DatePicker>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="!isDisableEdit">
          <div class="more-settings" @click="handleUnfoldMoreSettings">
            <span v-if="formItem.isUnfoldMoreSettings" class="more-settings-text">收起更多设置</span>
            <span v-if="!formItem.isUnfoldMoreSettings" class="more-settings-text">展开更多设置</span>
            <img v-if="formItem.isUnfoldMoreSettings" class="more-settings-icon" src="../../assets/images/fold.png" alt="">
            <img v-if="!formItem.isUnfoldMoreSettings"  class="more-settings-icon" src="../../assets/images/unfold.png" alt="">
          </div>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings || isDisableEdit">
          <Col span="11">
            <FormItem label="不可用日期" style="margin-bottom: 14px;">
              <div v-if="isDisableEdit">
                <span v-if="!formItem.invalidDateList || formItem.invalidDateList.length < 1">
                  -------
                </span>
                <span v-else>
                  <span
                    class="disable-date-values"
                    v-for="(item, index) in formItem.invalidDateList"
                    :key="item.id"
                    :style="{ marginTop: ((index > 0 ? 1 : 0) * 15) + 'px' }"
                  >
                    {{item.dateOfStart + ' — ' + item.dateOfEnd}}
                  </span>
                </span>
              </div>
              <div v-else>
                <div
                  class="disable-date-pickers"
                  v-for="(item, index) in formItem.invalidDateList"
                  :key="item.id"
                  :style="{ marginTop: ((index > 0 ? 1 : 0) * 15) + 'px' }"
                >
                  <DatePicker
                    type="daterange"
                    :disabled="isDisableEdit"
                    :options="optionTime"
                    format="yyyy-MM-dd"
                    @on-change="(value) => handleCustomDisableDateChange(value, index)"
                    :value="item.dateRange"
                    :editable="false"
                    split-panels
                    :style="{ width: '300px'}"
                  >
                  </DatePicker>
                  <Button
                    class="disable-date-picker-delete"
                    @click="handleDeleteDisableDatePicker(index)"
                  >
                    删除
                  </Button>
                </div>
                <div class="disable-date-add">
                  <span
                    class="disable-date-add-text"
                    v-if="formItem.invalidDateList.length < 51"
                    @click="handleAddDisableDateRange"
                  >
                    添加一个日期段
                  </span>
                  <span class="disable-date-add-tip">该促销活动在指定日期不生效</span>
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings || isDisableEdit">
          <Col span="13">
            <FormItem label="活动星期" style="margin-bottom: 14px;" prop="activityMatchDayOfWeek">
              <Checkbox
                v-if="!isDisableEdit"
                :indeterminate="activityDaysOfWeekIndeterminate"
                :value="checkActivityDaysOfWeekAll"
                @on-change="handleCheckActivityDaysOfWeekAll"
              >
                全选
              </Checkbox>
              <CheckboxGroup v-model="checkActivityDaysOfWeekAllGroup" @on-change="handleCheckActivityDaysOfWeekAllGroupChange">
                <Checkbox label="星期一" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期二" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期三" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期四" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期五" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期六" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期日" :disabled="isDisableEdit"></Checkbox>
              </CheckboxGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings">
          <Col span="11">
            <FormItem label="活动时间" style="margin-bottom: 14px;">
              <TimePicker
                type="time"
                format="HH:mm"
                @on-change="handleActivityTimeStartChange"
                :value="formItem.activityTimeStart"
                :editable="false"
                split-panels
                style="width: 135px"
              >
              </TimePicker>
              <span class="activity-time-separation-text">至</span>
              <TimePicker
                type="time"
                format="HH:mm"
                @on-change="handleActivityTimeEndChange"
                :value="formItem.activityTimeEnd"
                :editable="false"
                split-panels
                style="width: 135px"
              >
              </TimePicker>
            </FormItem>
          </Col>
        </Row>
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动规则</span>
        <Row :gutter="20">
          <Col span="11">
            <FormItem label="每单是否限购" style="margin-bottom: 14px;" prop="orderRuleLimitStatus">
              <div style="display: flex">
                <RadioGroup
                  v-model="formItem.orderRuleLimitStatus"
                  @on-change="handleOrderRuleLimitStatusChange"
                >
                  <Radio label="0" :disabled="isDisableEdit" checked>不限购</Radio>
                  <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">限购</Radio>
                </RadioGroup>
                <Input
                  v-if="formItem.orderRuleLimitStatus == 1"
                  v-model="formItem.orderRuleLimitCount"
                  :disabled="isDisableEdit"
                  style="width: 120px;margin-left: 10px;"
                  placeholder=""
                >
                  <span slot="append" style="color: #ffffff">份</span>
                </Input>
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="11">
            <FormItem label="同一商品" style="margin-bottom: 14px;" prop="productMultipartRuleLimitStatus">
              <div style="display: flex">
                <RadioGroup
                  v-model="formItem.productMultipartRuleLimitStatus"
                  @on-change="handleOrderRuleLimitStatusChange"
                >
                  <Radio label="0" :disabled="isDisableEdit" checked>不限购</Radio>
                  <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">限购</Radio>
                </RadioGroup>
                <Input
                  v-if="formItem.productMultipartRuleLimitStatus == 1"
                  v-model="formItem.productMultipartRuleLimitCount"
                  :disabled="isDisableEdit"
                  style="width: 120px;margin-left: 10px;"
                  placeholder=""
                >
                  <span slot="append" style="color: #ffffff">份</span>
                </Input>
              </div>
            </FormItem>
          </Col>
        </Row>
        <div v-for="(rule, ruleIndex) in formItem.activityInfoRuleList">
          <div style="display: flex;">
            <span style="display: inline-block;width: 320px;height: 20px;line-height: 20px;font-size: 13px;margin-left: 15px;">规则{{ ruleIndex + 1 }}</span>
            <Button
              v-if="!isDisableEdit && formItem.activityInfoRuleList.length > 1"
              class="disable-date-picker-delete"
              @click="handleDeleteInfoRuleList(ruleIndex)"
            >
              删除
            </Button>
          </div>
          <Row :gutter="20">
            <Col span="9">
              <FormItem
                label="折扣率"
                :prop="'activityInfoRuleList.' + ruleIndex + '.activityRuleRate'"
                :rules="dynamicRules.inputNumberCheck"
              >
                <Input
                  v-model="rule.activityRuleRate"
                  :disabled="isDisableEdit"
                  style="width: 200px"
                  placeholder="打7折，请输入70"
                >
                <span slot="append" style="color: #ffffff">%</span>
                </Input>
              </FormItem>
            </Col>
          </Row>
          <Row :gutter="20">
            <Col span="21">
              <FormItem
                label="折扣商品"
                style="margin-bottom: 14px;"
                :prop="'activityInfoRuleList.' + ruleIndex + '.activityProducts'"
                :rules="dynamicRules.activityProductsCheck"
              >
                <span
                  v-if="!isDisableEdit"
                  class="activity-product-target-category-text-add"
                  @click="activityProductChoice(ruleIndex)"
                >
                  选择商品（已选{{ rule.activityProducts ? rule.activityProducts.length : '0' }}个）
                </span>
                <span
                  v-else
                >
                  已选{{ rule.activityProducts ? rule.activityProducts.length : '0' }}种
                </span>
                <div
                  class="activity-product-target-category-list product-discount-list"
                  v-if="rule.activityProducts && rule.activityProducts.length"
                >
                  <div
                    class="activity-product-target-category-list-cell"
                    v-for="(item, productIndex) in rule.activityProducts"
                  >
                    <span
                      :class="`${isDisableEdit ? 'activity-product-target-category-list-cell-text-disable' : 'activity-product-target-category-list-cell-text'}`"
                    >
                      {{ item.productName }}
                    </span>
                    <img
                      v-if="!isDisableEdit"
                      src="../../assets/images/delete.png"
                      alt=""
                      class="activity-product-target-category-list-cell-img"
                      @click="deleteSelectedActivityRuleProduct(ruleIndex, productIndex)"
                    />
                  </div>
                </div>
                <!-- <span v-if="!rule.activityProducts || rule.activityProducts.length == 0" style="display: block;color: #ed4014;font-size: 12px;">折扣商品必须选择</span> -->
              </FormItem>
            </Col>
          </Row>
        </div>
        <div
          class="discount-rule-of-product-add"
          v-if="formItem.activityInfoRuleList.length < 20"
        >
          <span
            v-if="!isDisableEdit"
            class="discount-rule-of-product-add-text"
            @click="handleAddDiscountRuleOfProduct"
          >
            添加一条折扣规则
          </span>
        </div>
        <Row :gutter="20">
          <Col span="21">
            <FormItem label="活动说明">
              <Input
                v-model="formItem.activityDescription"
                :disabled="isDisableEdit"
                type="textarea"
                placeholder="请输入活动说明信息"
                :autosize="{minRows: 4,maxRows: 6}"
              />
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button v-if="!isDisableEdit" style="margin-left: 8px" @click="handleCancel">取消</Button>
        <Button v-if="!isDisableEdit" type="primary" @click="handleSubmit('productDiscountFormItem')">保存</Button>
      </div>
    </Modal>
    <Modal
      :title="modalTitle"
      :mask-closable="false"
      :closable="isDisableEdit"
      class="formTop"
      v-model="showRuleDiscountModal"
      width="70%"
    >
      <Form
        ref="ruleDiscountFormItem"
        :model="formItem"
        :label-width="90"
        :rules="formRules"
        class="form-box"
      >
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动基础信息</span>
        <Row :gutter="20">
          <Col span="9">
            <FormItem label="活动名称" prop="activityName">
              <Input
                v-model="formItem.activityName"
                :disabled="isDisableEdit"
                placeholder="请输入活动名称"
              />
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动对象" style="margin-bottom: 14px;" prop="activityMatchUserType">
              <RadioGroup v-model="formItem.activityMatchUserType">
                <Radio label="0" :disabled="isDisableEdit" checked>全部顾客</Radio>
                <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">仅会员</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动渠道" style="margin-bottom: 14px;">
              <Checkbox
                v-model="formItem.activityChannelPosType"
                :disabled="true"
              >
                收银机
              </Checkbox>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="accountType == 'company'">
          <Col span="23">
            <FormItem label="活动门店" style="margin-bottom: 14px;width: 90%" prop="activeShopList">
                <div v-if="isDisableEdit">
                  <span
                  >
                    {{formItem.activeShopList.length == storeList.length ? '全部门店' : formItem.activeShopList.length + '家门店'}}
                  </span>
                </div>
                <div v-else>
                  <span
                    class="activity-shop-desc"
                    @click="activityShopChoice"
                    v-if="formItem.activeShopList.length != 0 && formItem.activeShopList.length == storeList.length"
                  >
                    请选择门店（已选全部门店）
                  </span>
                  <span
                    class="activity-shop-desc"
                    @click="activityShopChoice"
                    v-else
                  >
                    请选择门店（已选{{ formItem.activeShopList.length }}个）
                  </span>
                </div>
              <div
                class="activity-product-target-category-list"
                v-if="formItem.activeShopList.length && !isDisableEdit"
              >
                <div
                  class="activity-product-target-category-list-cell"
                  v-for="(item, index) in formItem.activeShopList"
                >
                  <span
                    class="activity-product-target-category-list-cell-text"
                  >
                    {{ item.storeName }}
                  </span>
                  <img
                    src="../../assets/images/delete.png"
                    alt=""
                    class="activity-product-target-category-list-cell-img"
                    @click="handleDeleteSelectedActivityShop(index)"
                  />
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动日期</span>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="活动日期" style="margin-bottom: 14px;" prop="activityDateType">
              <RadioGroup v-model="formItem.activityDateType">
                <Radio label="0" :disabled="isDisableEdit" checked>永久有效</Radio>
                <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">自定义日期</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.activityDateType == '1'">
          <Col span="9">
            <FormItem label="自定义日期" style="margin-bottom: 14px;">
              <div v-if="isDisableEdit">
                {{formItem.activityDateStart + ' — ' + formItem.activityDateEnd}}
              </div>
              <DatePicker
                v-else
                type="daterange"
                :options="optionTime"
                format="yyyy-MM-dd"
                @on-change="handleCustomDateChange"
                :value="formItem.activityDateRange"
                :editable="false"
                split-panels
                style="width: 300px"
              >
              </DatePicker>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="!isDisableEdit">
          <div class="more-settings" @click="handleUnfoldMoreSettings">
            <span v-if="formItem.isUnfoldMoreSettings" class="more-settings-text">收起更多设置</span>
            <span v-if="!formItem.isUnfoldMoreSettings" class="more-settings-text">展开更多设置</span>
            <img v-if="formItem.isUnfoldMoreSettings" class="more-settings-icon" src="../../assets/images/fold.png" alt="">
            <img v-if="!formItem.isUnfoldMoreSettings" class="more-settings-icon" src="../../assets/images/unfold.png" alt="">
          </div>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings || isDisableEdit">
          <Col span="11">
            <FormItem label="不可用日期" style="margin-bottom: 14px;">
              <div v-if="isDisableEdit && (!formItem.invalidDateList || formItem.invalidDateList.length < 1)">
                -------
              </div>
              <div v-else>
                <div
                  class="disable-date-pickers"
                  v-for="(item, index) in formItem.invalidDateList"
                  :key="item.id"
                  :style="{ marginTop: ((index > 0 ? 1 : 0) * 15) + 'px' }"
                >
                  <DatePicker
                    type="daterange"
                    :disabled="isDisableEdit"
                    :options="optionTime"
                    format="yyyy-MM-dd"
                    @on-change="(value) => handleCustomDisableDateChange(value, index)"
                    :value="item.dateRange"
                    :editable="false"
                    split-panels
                    :style="{ width: '300px'}"
                  >
                  </DatePicker>
                  <Button
                    v-if="!isDisableEdit"
                    class="disable-date-picker-delete"
                    @click="handleDeleteDisableDatePicker(index)"
                  >
                    删除
                  </Button>
                </div>
                <div class="disable-date-add">
                  <span
                    class="disable-date-add-text"
                    v-if="formItem.invalidDateList.length < 51 && !isDisableEdit"
                    @click="handleAddDisableDateRange"
                  >
                    添加一个日期段
                  </span>
                  <span class="disable-date-add-tip">该促销活动在指定日期不生效</span>
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings || isDisableEdit">
          <Col span="13">
            <FormItem label="活动星期" style="margin-bottom: 14px;" prop="activityMatchDayOfWeek">
              <Checkbox
                v-if="!isDisableEdit"
                :indeterminate="activityDaysOfWeekIndeterminate"
                :value="checkActivityDaysOfWeekAll"
                @on-change="handleCheckActivityDaysOfWeekAll"
              >
                全选
              </Checkbox>
              <CheckboxGroup v-model="checkActivityDaysOfWeekAllGroup" @on-change="handleCheckActivityDaysOfWeekAllGroupChange">
                <Checkbox label="星期一" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期二" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期三" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期四" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期五" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期六" :disabled="isDisableEdit"></Checkbox>
                <Checkbox label="星期日" :disabled="isDisableEdit"></Checkbox>
              </CheckboxGroup>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20" v-if="formItem.isUnfoldMoreSettings || isDisableEdit">
          <Col span="11">
            <FormItem label="活动时间" style="margin-bottom: 14px;">
              <TimePicker
                :disabled="isDisableEdit"
                type="time"
                format="HH:mm"
                @on-change="handleActivityTimeStartChange"
                :value="formItem.activityTimeStart"
                :editable="false"
                split-panels
                style="width: 135px"
              >
              </TimePicker>
              <span class="activity-time-separation-text">至</span>
              <TimePicker
                :disabled="isDisableEdit"
                type="time"
                format="HH:mm"
                @on-change="handleActivityTimeEndChange"
                :value="formItem.activityTimeEnd"
                :editable="false"
                split-panels
                style="width: 135px"
              >
              </TimePicker>
            </FormItem>
          </Col>
        </Row>
        <span style="display: inline-block;width: 100%;height: 30px;line-height: 20px;font-size: 14px;font-weight: bold;">活动规则</span>
        <Row :gutter="20">
          <Col span="7">
            <FormItem label="优惠方式" style="margin-bottom: 14px;" prop="activityProductConditionIncreaseStatus">
              <RadioGroup v-model="formItem.activityProductConditionIncreaseStatus">
                <Radio label="0" :disabled="isDisableEdit" checked>满赠</Radio>
                <Radio label="1" :disabled="isDisableEdit" style="margin-left: 10px;">每满赠</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <div
          v-for="(item, ruleIndex) in formItem.activityInfoRuleProductGiveList"
          :style="`${ruleIndex > 0 ? 'marginTop: 10px' : 'marginTop: 0px'}`"
        >
          <Row
            :gutter="20"
          >
            <Col span="21">
              <FormItem
                style="margin-bottom: 14px;"
                :label="ruleIndex > 0 ? '' : '优惠条件'"
                :prop="'activityInfoRuleProductGive' + ruleIndex"
                :rules="dynamicRules.productGiveCheck"
              >
                <div class="preferential-conditions-list-item-row">
                  <span class="preferential-conditions-list-item-default-text">消费商品： 满</span>
                  <Input
                    v-model="item.conditionAmount"
                    :disabled="isDisableEdit"
                    style="width: 120px;margin-left: 5px;"
                    placeholder=""
                  >
                    <span slot="append" style="color: #ffffff">元</span>
                  </Input>
                  <span
                    class="preferential-conditions-list-item-default-text"
                    style="margin-left: 5px;"
                  >
                    赠送
                  </span>
                  <Input
                    v-model="item.giveCount"
                    :disabled="isDisableEdit"
                    style="width: 120px;margin-left: 5px;"
                    placeholder=""
                  >
                    <span slot="append" style="color: #ffffff">份</span>
                  </Input>
                  <span
                    class="preferential-conditions-list-item-default-text"
                    style="margin-left: 5px;"
                  >
                    以下商品
                  </span>
                  <span
                    class="preferential-conditions-list-item-consumption-tips"
                    style="margin-left: 7px;"
                  >
                    若选择多个商品，代表从中任选一份
                  </span>
                  <Button
                    class="disable-date-picker-delete"
                    v-if="ruleIndex > 0 && !isDisableEdit"
                    @click="handleDeletePreferentialConditionsItem(ruleIndex)"
                  >
                    删除
                  </Button>
                </div>
                <div class="preferential-conditions-list-item-present-row">
                  <span class="preferential-conditions-list-item-default-text">赠送商品： </span>
                  <span
                    v-if="isDisableEdit"
                  >
                    已选{{ item.giveProductList.length }}个
                  </span>
                  <span
                    v-else
                    @click="activityProductChoice(ruleIndex)"
                    class="preferential-conditions-list-item-select-text"
                  >
                    选择商品（已选{{ item.giveProductList.length }}个）
                  </span>
                </div>
                <div
                  class="activity-product-target-category-list product-discount-list"
                  v-if="item.giveProductList.length"
                >
                  <div
                    :class="`${isDisableEdit ? 'activity-product-target-category-list-cell disable' : 'activity-product-target-category-list-cell'}`"
                    v-for="(item, productIndex) in item.giveProductList"
                  >
                    <span
                      :class="`${isDisableEdit ? 'activity-product-target-category-list-cell-text-disable' : 'activity-product-target-category-list-cell-text'}`"
                    >
                      {{ item.productName }}
                    </span>
                    <img
                      v-if="!isDisableEdit"
                      src="../../assets/images/delete.png"
                      alt=""
                      class="activity-product-target-category-list-cell-img"
                      @click="deleteSelectedActivityRuleProduct(ruleIndex, productIndex)"
                    />
                  </div>
                </div>
              </FormItem>
            </Col>
          </Row>
        </div>
        <div
          class="preferential-conditions-add"
          v-if="formItem.activityProductConditionIncreaseStatus == '0' && formItem.activityInfoRuleList.length < 20 && !isDisableEdit"
        >
          <span
            class="discount-rule-of-product-add-text"
            @click="handleAddPreferentialConditionsItem"
          >
            添加一条规则
          </span>
        </div>
        <Row :gutter="20">
          <Col span="21">
            <FormItem label="适用商品" style="margin-bottom: 14px;" prop="activityProductTargetFlag">
              <RadioGroup v-model="formItem.activityProductConditionType">
                <Radio label="0" :disabled="isDisableEdit" checked>全部商品</Radio>
                <Radio v-if="accountType == 'store'" label="1" :disabled="isDisableEdit" style="margin-left: 10px;">部分可用</Radio>
              </RadioGroup>
              <div
                class="activity-product-target-category"
                v-if="formItem.activityProductConditionType == '1'"
              >
                <div class="activity-product-target-category-text">
                  <span class="activity-product-target-category-text-title">指定分类：</span>
                  <span
                    v-if="isDisableEdit"
                  >
                    已选{{ formItem.activityProductTypes.length }}个
                  </span>
                  <span
                    v-else
                    class="activity-product-target-category-text-add"
                    @click="activityProductTargetCategoryChoice"
                  >
                    选择分类（已选{{ formItem.activityProductTypes.length }}个）
                  </span>
                  <span class="activity-product-target-category-text-desc">
                    如选择指定类别，后期分类中增加商品自动适用当前活动
                  </span>
                </div>
                <div
                  class="activity-product-target-category-list"
                  v-if="formItem.activityProductTypes.length"
                >
                  <div
                    :class="`${isDisableEdit ? 'activity-product-target-category-list-cell disable' : 'activity-product-target-category-list-cell'}`"
                    v-for="(item, index) in formItem.activityProductTypes"
                  >
                    <span
                      :class="`${isDisableEdit ? 'activity-product-target-category-list-cell-text-disable' : 'activity-product-target-category-list-cell-text'}`"
                    >
                      {{ item.className }}
                    </span>
                    <img
                      v-if="!isDisableEdit"
                      src="../../assets/images/delete.png"
                      alt=""
                      class="activity-product-target-category-list-cell-img"
                      @click="deleteSelectedActivityProductTargetCategory(index)"
                    />
                  </div>
                </div>
              </div>
              <div
                class="activity-product-target"
                v-if="formItem.activityProductConditionType == '1'"
              >
                <div class="activity-product-target-category-text">
                  <span class="activity-product-target-category-text-title">指定商品：</span>
                  <span
                    v-if="isDisableEdit"
                  >
                    已选{{ formItem.activityProducts.length }}个
                  </span>
                  <span
                    v-else
                    class="activity-product-target-category-text-add"
                    @click="activityProductChoice(-1)"
                  >
                    选择商品（已选{{ formItem.activityProducts.length }}个）
                  </span>
                </div>
                <div
                  class="activity-product-target-category-list"
                  v-if="formItem.activityProducts.length"
                >
                  <div
                    :class="`${isDisableEdit ? 'activity-product-target-category-list-cell disable' : 'activity-product-target-category-list-cell'}`"
                    v-for="(item, index) in formItem.activityProducts"
                  >
                    <span
                      :class="`${isDisableEdit ? 'activity-product-target-category-list-cell-text-disable' : 'activity-product-target-category-list-cell-text'}`"
                    >
                      {{ item.productName }}
                    </span>
                    <img
                      v-if="!isDisableEdit"
                      src="../../assets/images/delete.png"
                      alt=""
                      class="activity-product-target-category-list-cell-img"
                      @click="deleteSelectedActivityProduct(index)"
                    />
                  </div>
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="20">
          <Col span="21">
            <FormItem label="活动说明">
              <Input
                v-model="formItem.activityDescription"
                :disabled="isDisableEdit"
                type="textarea"
                placeholder="请输入活动说明信息"
                :autosize="{minRows: 4,maxRows: 6}"
              />
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button v-if="!isDisableEdit" style="margin-left: 8px" @click="handleCancel">取消</Button>
        <Button v-if="!isDisableEdit" type="primary" @click="handleSubmit('ruleDiscountFormItem')">保存</Button>
      </div>
    </Modal>
    <Modal :mask-closable="false" v-model="showCancelPrompt" width="360">
      <p slot="header" style="color:#f60;text-align:center">
        <Icon type="ios-information-circle"></Icon>
        <span>确定退出吗？</span>
      </p>
      <div style="text-align:center">
        <p>未保存档内容将会丢失</p>
      </div>
      <div slot="footer">
        <Button type="error" size="large" long @click="handleCancelSure">退出</Button>
      </div>
    </Modal>
    <Modal
      :mask-closable="false"
      class="formTop"
      v-model="showShopListModal"
      title="选择活动门店"
      width="40%"
      @on-cancel="closeShopListModal"
    >
      <Table
        ref="activityStoreListSelection"
        :columns="shopSelectTableColumns"
        :data="storeList"
        @on-selection-change="shopListSelectedChange"
      >
      </Table>
      <div slot="footer" v-if="!isDisableEdit">
        <Button style="margin-right: 65%;" @click="handleShopSelectModalReset" type="warning">清空</Button>
        <Button style="margin-left: 8px" @click="handleShopSelectModalCancel">取消</Button>
        <Button type="primary" @click="handleShopSelectModalSure">确定</Button>
      </div>
    </Modal>
    <Modal
      :mask-closable="false"
      class="formTop"
      v-model="showProductCategoryModal"
      title="选择分类"
      width="40%"
      @on-cancel="closeProductCategoryModal"
    >
      <div class="iu-tree1">
        <Tree
          :data="productCategoryTreeData"
          :show-checkbox="true"
          :multiple="true"
          @on-check-change="productCategoryTreeSelcted"
          class="product-category-select-tree"
        >
        </Tree>
      </div>
      <div slot="footer" v-if="!isDisableEdit">
        <Button style="margin-right: 65%;" @click="handleProductCategoryModalReset" type="warning">清空</Button>
        <Button style="margin-left: 8px" @click="handleProductCategoryModalCancel">取消</Button>
        <Button type="primary" @click="handleProductCategoryModalSubmit">确定</Button>
      </div>
    </Modal>
    <Modal
      :mask-closable="false"
      class="formTop"
      v-model="showProductListModal"
      title="选择商品"
      width="40%"
      @on-cancel="closeProductListModal"
    >
      <div class="product-select-modal-content">
        <Tree
          :data="productCategoryTreeOriginalData"
          @on-select-change="productSelectTreeSelcted"
          class="product-select-tree"
        >
        </Tree>
        <Table
          width="450"
          height="300"
          ref="selection"
          :columns="productSelectTableColumns"
          :data="productTableData"
          @on-selection-change="productListSelectedChange"
          style="margin-left: auto;"
        >
        </Table>
      </div>
      <div slot="footer" v-if="!isDisableEdit">
        <Button style="margin-right: 65%;" @click="handleProductSelectModalReset" type="warning">清空</Button>
        <Button style="margin-left: 8px" @click="handleProductSelectModalCancel">取消</Button>
        <Button type="primary" @click="handleProductSelectModalSure">确定</Button>
      </div>
    </Modal>
  </div>
</template>
<script>
import { Format, generateRandom, buildTree } from "@/assets/util";
import {
  chainActivityManageDetail, // 连锁-查询活动详情
  storeActivityManageDetail // 单店-查询活动详情
} from "@/api/order";
import {
  chainQueryBindStoreList
} from "@/api/loginMenu";
import { productClassFindList } from "@/api/goods";
import { productFindPage } from "@/api/product";
export default {
  name: "sellPromotionModal",
  data() {
    // 0-99整数校验
    const intNumberCheck = async(value, callback) => {
      var regex = /^\d+$/;
      var isNumber = regex.test(value);
      if (isNumber) {
        if (parseInt(value) > 99) {
          return callback(new Error('请输入0~99之间的整数'));
        } else {
          return callback();
        }
      } else {
        return callback(new Error('请输入0~99之间的整数'));
      }
    };
    // 整单折扣率合规校验
    const activityRuleRateValidityCheck = async(rule, value, callback) => {
      return intNumberCheck(this.formItem.activityRuleRate, callback);
    };
    // 每单限购数量输入校验
    const orderRuleLimitCountCheck = async(rule, value, callback) => {
      debugger;
      return intNumberCheck(this.formItem.orderRuleLimitCount, callback);
    };
    // 同一商品数量输入校验
    const productMultipartRuleLimitCountCheck = async(rule, value, callback) => {
      return intNumberCheck(this.formItem.productMultipartRuleLimitCount, callback);
    };
    // 整单折扣率空值校验
    const activityRuleRateEmptyCheck = async(rule, value, callback) => {
      if (!this.formItem.activityRuleRate || this.formItem.activityRuleRate == '') {
        return callback(new Error('整单折扣率必须填写'));
      } else {
        callback()
      }
    };
    // 折扣商品选择校验
    const activityProductCheck = async(rule, value, callback) => {
      debugger;
      if (!this.formItem.activityRuleRate || this.formItem.activityRuleRate == '') {
        return callback(new Error('整单折扣率必须填写'));
      } else {
        callback()
      }
    };
    // 动态表单输入数值校验
    const dynamicRuleRateValidityCheck = (rule, value, callback) => {
      if (!rule.field || rule.field.length < 1) {
        return callback(new Error('折扣率必须填写'));
      }

      let strArr = rule.field.split('.');
      let index = parseInt(strArr[1]);
      let activityRuleRate = this.formItem.activityInfoRuleList[index].activityRuleRate;
      return intNumberCheck(activityRuleRate, callback);
    };
    // 动态表单选择商品校验
    const dynamicActivityProductsCheck = (rule, value, callback) => {
      if (!rule.field || rule.field.length < 1) {
        return callback(new Error('折扣商品必须选择'));
      }

      let strArr = rule.field.split('.');
      let index = parseInt(strArr[1]);
      let activityProducts = this.formItem.activityInfoRuleList[index].activityProducts;
      if (!activityProducts || activityProducts.length < 1) {
        return callback(new Error('折扣商品必须选择'));
      } else {
        return callback();
      }
    };
    // 动态表单输入优惠条件校验
    const dynamicProductGiveCheckCheck = (rule, value, callback) => {
      let index = parseInt(rule.fullField.substring(27, rule.fullField.length));
      let giveValue = this.formItem.activityInfoRuleProductGiveList[index];

      if (!giveValue.conditionAmount || giveValue.conditionAmount.length < 1) {
        return callback(new Error('满赠金额条件必须填写'));
      } else if (giveValue.conditionAmount == '0') {
        return callback(new Error('满赠金额条件不能为0'));
      } else {
        var regex1 = /^[0-9.]+$/;
        var isNumber1 = regex1.test(giveValue.conditionAmount);
        if (!isNumber1) {
          return callback(new Error('满赠金额条件只能由数字和.组成'));
        }
      }

      if (!giveValue.giveCount || giveValue.giveCount.length < 1) {
        return callback(new Error('请输入满赠份数'));
      }
      var regex2 = /^\d+$/;
      var isNumber2 = regex2.test(giveValue.giveCount);
      if (!isNumber2) {
        return callback(new Error('满赠份数请输入整数'));
      }

      if (!giveValue.giveProductList || giveValue.giveProductList.length < 1) {
        return callback(new Error('赠送商品必须选择'));
      }

      return callback();
    };
    return {
      dynamicRules: {
        inputNumberCheck: [
          { required: true, validator: dynamicRuleRateValidityCheck }
        ],
        activityProductsCheck: [
          { required: true, validator: dynamicActivityProductsCheck }
        ],
        productGiveCheck: [
          { required: true, validator: dynamicProductGiveCheckCheck }
        ]
      },
      accountType: 'store', // 登录类型默认为单店
      type: 0, // 0：创建整单折扣 1：创建商品折扣 2：创建满增/每满增 3：查看整单折扣 4：查看商品折扣 5：查看满增/每满增 6：编辑整单折扣 7：编辑商品折扣 8：编辑满增/每满增
      modalTitle: "", // 标题
      isDisableEdit: true, // 是否可编辑
      showCancelPrompt: false, // 显示退出创建/编辑提示
      showOrderDiscountModal: false, // 显示整单折扣
      showProductDiscountModal: false, // 显示商品折扣
      showRuleDiscountModal: false, // 显示满赠
      currentTempSelectedShopData: [], // 门店模态窗已勾选未保存的数据
      storeList: [], // 门店列表数据
      shopSelectTableColumns: [ // 选择商品模态窗列表列数据
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '门店名称',
          key: 'storeName'
        }
      ],
      normalDateRange: [], // 日期控件默认时间范围
      activityDaysOfWeekIndeterminate: false,
      checkActivityDaysOfWeekAll: true,
      checkActivityDaysOfWeekAllGroup: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'],
      activityTimeStart: '',
      formItem: {
        activityId: '', // 活动ID
        activityName: "", // 活动名称
        activityMatchUserType: "0", // 活动对象类型
        activityChannelPosType: true, // 活动渠道类型
        activeShopList: [], // 活动门店列表
        activityDateType: "0", // 活动日期类型
        activityDateStart: '', // 自定义开始日期
        activityDateEnd: '', // 自定义结束日期
        invalidDateList: [], // 不可用日期列表
        activityDateRange: [], // 自定义日期范围
        activityMatchDayOfWeek: '0,1,2,3,4,5,6', // 活动星期
        activityTimeOfDay: "", // 活动时间
        activityTimeStart: "", // 活动开始时间
        activityTimeEnd: "", // 活动结束时间
        orderRuleLimitStatus: "0", // 每单是否限购
        orderRuleLimitCount: "0", // 每单限购数量
        productMultipartRuleLimitStatus: "0", // 同一商品
        productMultipartRuleLimitCount: "0", // 同一商品限购数量
        activityInfoRuleList: [ // 商品折扣活动规则列表
          {
            index: 1,
            activityRuleRate: "", // 商品折扣活动规则折扣率
            activityProducts: [] // 商品折扣活动规则折扣商品
          }
        ],
        activityRuleRate: "", // 整单折扣率
        activityProductConditionType: "0", // 适用商品
        activityProductTypes: [], // 活动商品类型
        activityProducts: [], // 活动商品(创建整单促销活动使用)
        productListOwnerRuleIndex: 0, // 添加商品时归属条件的下标（创建商品促销、创建满赠促销使用）
        sellConcession: false, // 优惠条件
        activityProductConditionIncreaseStatus: "0", // 优惠方式：满赠/每满赠
        mark: "", // 活动说明
        isShowMoreSettings: false, // 是否显示更多设置
        isUnfoldMoreSettings: false, // 是否展开更多设置
        activityInfoRuleProductGiveList: [ // 优惠规则列表
          {
            index: 1,
            conditionAmount: "", // 满多少
            giveCount: "", // 赠多少
            giveProductList: [] // 选择的赠送商品列表
          }
        ],
        activityDescription: "" // 活动说明
      },
      formRules: {
        activityName: { required: true, message: "活动名称必须填写" },
        activityMatchUserType: { required: true },
        activeShopList: { required: true, message: "活动门店必须选择" },
        activityDateType: { required: true },
        activityDateRange: { required: true },
        activityMatchDayOfWeek: { required: true, message: "活动星期必须选择" },
        orderRuleLimitStatus: [
          { validator: orderRuleLimitCountCheck, trigger: 'change' }
        ],
        productMultipartRuleLimitStatus: [
          { validator: productMultipartRuleLimitCountCheck, trigger: 'change' }
        ],
        activityRuleRate: [
          { required: true, validator: activityRuleRateValidityCheck, trigger: 'blur' },
          { required: true, validator: activityRuleRateEmptyCheck, trigger: 'blur' },
          { required: true, validator: activityRuleRateValidityCheck, trigger: 'change' },
          { required: true, validator: activityRuleRateEmptyCheck, trigger: 'change' }
        ],
        sellConcession: { required: true, message: "优惠条件必须填写" },
        activityDiscountOfProduct: [
          { required: true, validator: orderRuleLimitCountCheck, trigger: 'change' }
        ],
        activityProductConditionIncreaseStatus: { required: true }
      },
      optionTime: {
        shortcuts: [
          {
            text: "今日",
            value() {
              const start = new Date();
              const end = new Date();

              start.setHours(0, 0, 0, 0);

              start.setTime(start.getTime());
              end.setTime(end.getTime());
              return [start, end];
            }
          },
          {
            text: "昨日",
            value() {
              const start = new Date();
              const end = new Date();

              start.setHours(0, 0, 0, 0);
              end.setHours(0, 0, 0, 0);

              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
              end.setTime(end.getTime() - 0.001);
              return [start, end];
            }
          },
          {
            text: "本周",
            value() {
              const start = new Date();
              const end = new Date();

              start.setHours(0, 0, 0, 0);

              let weekDay = start.getDay();
              let distance = weekDay - 1;
              if (weekDay === 0) {
                distance = 6;
              }

              start.setTime(start.getTime() - 3600 * 1000 * 24 * distance);
              end.setTime(end.getTime());
              return [start, end];
            }
          },
          {
            text: "本月",
            value() {
              const start = new Date();
              const end = new Date();

              start.setHours(0, 0, 0, 0);

              let firstDayOfMonth = new Date(start.getFullYear(), start.getMonth(), 1);
              firstDayOfMonth.setTime(firstDayOfMonth.getTime());
              return [firstDayOfMonth, end];
            }
          },
          {
            text: "上月",
            value() {
              let nowData = new Date();
              let currentMonth = nowData.getMonth();
              let currentYear = nowData.getFullYear();
              let start = new Date(currentYear, currentMonth - 1, 1);
              let end = new Date(currentYear, currentMonth, 0);
              return [start, end];
            }
          }
        ]
      },
      activityTime: {
      },
      showProductCategoryModal: false, // 是否显示选择商品分类模态窗
      productCategoryOriginalData: [], // 商品分类原始数据
      productCategoryTreeOriginalData: [], // 商品分类树原始数据
      productCategoryTreeData: [], // 商品分类数据
      showShopListModal: false, // 是否显示选择门店模态窗
      currentSelectedProductCategoryTreeData: [], // 商品分类选择模态窗已勾选的数据
      showProductListModal: false, // 是否显示选择商品模态窗
      currentTempSelectedProductData: [], // 商品模态窗已勾选未保存的数据
      productSelectTableColumns: [ // 选择商品模态窗列表列数据
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '商品名称',
          key: 'productName'
        }
      ],
      productTableCacheData: {}, // 缓存商品选择列表的数据 { classCode: productListData }
      productTableData: [], // 商品列表数据
      currentTreeNode: {},
      classCode: "",
      pid: "",
      fastQuery: "",
      pageNum: 1,
      pageSize: 10,
      mark: "" // 备注
    }
  },
  methods: {
    init(item, activityType, isDisableEdit) {
      this.type = activityType;
      this.isDisableEdit = isDisableEdit;
      this.accountType = localStorage.getItem('userLoginType');
      if (this.accountType == 'store') {
        let storeInfoJSON = localStorage.getItem('storeInfo');
        let storeInfo = JSON.parse(storeInfoJSON);
        this.storeCode = storeInfo.storeCode;
      }

      this.setNormalDateRange();
      if (this.type == 0) {
        this.modalTitle = "创建整单折扣活动";
        this.showOrderDiscountModal = true;
        if (this.accountType == 'company') {
          this.queryChainStoreList();
        }
      } else if (this.type == 1) {
        this.modalTitle = "创建商品折扣活动";
        this.showProductDiscountModal = true;
        if (this.accountType == 'company') {
          this.queryChainStoreList();
        }
      } else if (this.type == 2) {
        this.modalTitle = "创建满赠/每满增活动";
        this.showRuleDiscountModal = true;
        if (this.accountType == 'company') {
          this.queryChainStoreList();
        }
      } else if (this.type == 3) {
        this.modalTitle = "查看活动详情";
        this.showOrderDiscountModal = true;
        this.formItem.activityId = item.id;
        this.activityManageDetail();
      } else if (this.type == 4) {
        this.modalTitle = "查看活动详情";
        this.showProductDiscountModal = true;
        this.formItem.activityId = item.id;
        this.activityManageDetail();
      } else if (this.type == 5) {
        this.modalTitle = "查看活动详情";
        this.showRuleDiscountModal = true;
        this.formItem.activityId = item.id;
        this.activityManageDetail();
      } else if (this.type == 6) {
        this.modalTitle = "编辑活动详情";
        this.showOrderDiscountModal = true;
        this.formItem.activityId = item.id;
        this.activityManageDetail();
      } else if (this.type == 7) {
        this.modalTitle = "编辑活动详情";
        this.showProductDiscountModal = true;
        this.formItem.activityId = item.id;
        this.activityManageDetail();
      } else if (this.type == 8) {
        this.modalTitle = "编辑活动详情";
        this.showRuleDiscountModal = true;
        this.formItem.activityId = item.id;
        this.activityManageDetail();
      }

      this.customStyle();
    },
    // 修改样式
    customStyle() {
      setTimeout(() => {
        this.costomUnitOfInputViewStyle();
      }, 500);
    },
    // 修改输入框的单位背景色
    costomUnitOfInputViewStyle() {
      // 修改整单折扣率%背景色
      var ivuInputSearchElements = document.getElementsByClassName("ivu-input-group-append");
      for (let i = 0; i < ivuInputSearchElements.length; i++) {
        let unitElement = ivuInputSearchElements[i];
        if (this.isDisableEdit) {
          unitElement.style.setProperty("background-color", "lightgray", "important");
          unitElement.style.setProperty("border-color", "lightgray", "important");
          unitElement.style.setProperty("width", "32px", "important");
        } else {
          unitElement.style.setProperty("background-color", "#57a3f3", "important");
          unitElement.style.setProperty("border-color", "#57a3f3", "important");
          unitElement.style.setProperty("width", "32px", "important");
        }
      }
    },
    // 连锁创建活动请求门店列表
    queryChainStoreList() {
      const Loading = this.$myLoading();
      Promise.all([this.queryBranchStoreList()]).then((result) => {
        if (result && result.length > 0) {
          this.storeList = result[0];
        }
        this.closeLoading(Loading);
      });
    },
    // 查看活动详情数据配置
    configActivityDetailData(data) {
      var detailData = data;
      if (this.accountType == 'company') {
        detailData = data.activityInfo;
        this.formItem.activeShopList = data.storeInfoList;
      }

      if (this.type == 3) {
        this.configOrderDiscountModalData(detailData);
      } else if (this.type == 4) {
        this.configProductDiscountModalData(detailData);
      } else if (this.type == 5) {
        this.configRuleDiscountModalData(detailData);
      } else if (this.type == 6) {
        this.configOrderDiscountModalData(detailData);
      } else if (this.type == 7) {
        this.configProductDiscountModalData(detailData);
      } else if (this.type == 8) {
        this.configRuleDiscountModalData(detailData);
      }
    },
    // 设置整单促销活动详情显示
    configOrderDiscountModalData(data) {
      this.formItem.activityName = data.activityName;
      this.formItem.activityMatchUserType = data.activityMatchUserType + '';
      this.formItem.activityDateType = data.activityDateType + '';
      this.formItem.activityMatchDayOfWeek = data.activityMatchDayOfWeek;
      this.formItem.activityTimeStart = data.activityTimeStart;
      this.formItem.activityTimeEnd = data.activityTimeEnd;
      this.formItem.activityDescription = data.activityDescription;

      if (data.activityDateType == '1') {
        // 自定义日期
        this.formItem.activityDateStart = data.activityDateStart;
        this.formItem.activityDateEnd = data.activityDateEnd;
        this.formItem.activityDateRange = [data.activityDateStart, data.activityDateEnd];
      }

      // 不可用日期
      this.formItem.invalidDateList = [];
      if (data.activityInfoMatchDateList && data.activityInfoMatchDateList.length > 0) {
        for (let i = 0; i < data.activityInfoMatchDateList.length; i++) {
          let dateItem = data.activityInfoMatchDateList[i];
          this.formItem.invalidDateList.push({
            dateOfStart: dateItem.dateOfStart,
            dateOfEnd: dateItem.dateOfEnd,
            dateRange: [dateItem.dateOfStart, dateItem.dateOfEnd]
          });
        }
      }

      // 活动星期
      this.transformDataToActivityDaysOfWeek(data.activityMatchDayOfWeek);

      // 活动规则
      if (data.activityInfoRuleVOList.length > 0) {
        this.formItem.activityRuleRate = data.activityInfoRuleVOList[0].activityRuleRate + '';
        this.formItem.activityProductConditionType = data.activityInfoRuleVOList[0].activityProductConditionType + '';

        // 活动指定商品分类
        let activityProductClassConditionCodeListStr = data.activityInfoRuleVOList[0]['activityProductClassConditionCodeListStr'];
        if (activityProductClassConditionCodeListStr && activityProductClassConditionCodeListStr.length > 0) {
          var classCodes = activityProductClassConditionCodeListStr.split(',');
          var activityProductClassItems = [];

          // 在全部商品分类信息中查询商品分类信息
          if (classCodes.length > 0 && this.productCategoryOriginalData.length > 0) {
            for (let j = 0; j < classCodes.length; j++) {
              const classCode = classCodes[j];
              for (let k = 0; k < this.productCategoryOriginalData.length; k++) {
                const classItem = this.productCategoryOriginalData[k];
                if (classItem.classCode == classCode) {
                  activityProductClassItems.push(classItem);
                  if (activityProductClassItems.length == classCodes.length) {
                    break;
                  }
                }
              }
            }
          }
          this.formItem.activityProductTypes = activityProductClassItems;
        }

        // 活动指定商品
        let activityProductConditionCodeListStr = data.activityInfoRuleVOList[0]['activityProductConditionCodeListStr'];
        if (activityProductConditionCodeListStr && activityProductConditionCodeListStr.length > 0) {
          // var productCodes = activityProductConditionCodeListStr.split(',');
          // var activityProductsItems = [];

          // // 在全部商品信息中查询商品信息
          // if (productCodes.length > 0 && this.productTableCacheData['']) {
          //   for (let j = 0; j < productCodes.length; j++) {
          //     const productCode = productCodes[j];
          //     for (let k = 0; k < this.productTableCacheData[''].length; k++) {
          //       const productItem = this.productTableCacheData[''][k];
          //       if (productItem.productCode == productCode) {
          //         activityProductsItems.push(productItem);
          //         if (activityProductsItems.length == productCodes.length) {
          //           break;
          //         }
          //       }
          //     }
          //   }
          // }
          this.formItem.activityProducts = data.activityInfoRuleVOList[0].productList;
        }
      }
    },
    // 设置商品促销活动详情显示
    configProductDiscountModalData(data) {
      this.formItem.activityName = data.activityName;
      this.formItem.activityMatchUserType = data.activityMatchUserType + '';
      this.formItem.activityChannelList = data.activityChannelList;
      this.formItem.activityDateType = data.activityDateType + '';
      this.formItem.activityMatchDayOfWeek = data.activityMatchDayOfWeek;
      this.formItem.activityTimeStart = data.activityTimeStart;
      this.formItem.activityTimeEnd = data.activityTimeEnd;
      this.formItem.orderRuleLimitStatus = data.orderRuleLimitStatus + '';
      this.formItem.productMultipartRuleLimitStatus = data.productMultipartRuleLimitStatus + '';
      this.formItem.activityDescription = data.activityDescription;

      if (data.activityDateType == '1') {
        // 自定义日期
        this.formItem.activityDateStart = data.activityDateStart;
        this.formItem.activityDateEnd = data.activityDateEnd;
        this.formItem.activityDateRange = [data.activityDateStart, data.activityDateEnd];
      }

      // 不可用日期
      if (data.activityInfoMatchDateList && data.activityInfoMatchDateList.length > 0) {
        for (let i = 0; i < data.activityInfoMatchDateList.length; i++) {
          data.activityInfoMatchDateList[i]['dateRange'] = [data.activityInfoMatchDateList[i]['dateOfStart'], data.activityInfoMatchDateList[i]['dateOfEnd']];
        }
        this.formItem.invalidDateList = data.activityInfoMatchDateList;
      }

      // 活动星期
      this.transformDataToActivityDaysOfWeek(data.activityMatchDayOfWeek);

      // 每单限购数量
      if (data.orderRuleLimitStatus == '1') {
        this.formItem.orderRuleLimitCount = data.orderRuleLimitCount;
      }

      // 同一商品限购数量
      if (this.formItem.productMultipartRuleLimitStatus == '1') {
        this.formItem.productMultipartRuleLimitCount = data.productMultipartRuleLimitCount;
      }

      // 活动规则activityInfoRuleVOList
      if (data.activityInfoRuleVOList.length > 0) {
        this.formItem.activityInfoRuleList = [];

        for (var i = 0; i < data.activityInfoRuleVOList.length; i++) {
          var element = data.activityInfoRuleVOList[i];
          // var productCodes = element.activityProductConditionCodeListStr.split(',');
          // var activityProductsItems = [];

          // // 在全部商品信息中查询商品信息
          // if (productCodes.length > 0 && this.productTableCacheData['']) {
          //   for (let j = 0; j < productCodes.length; j++) {
          //     const productCode = productCodes[j];
          //     for (let k = 0; k < this.productTableCacheData[''].length; k++) {
          //       const productItem = this.productTableCacheData[''][k];
          //       if (productItem.productCode == productCode) {
          //         activityProductsItems.push(productItem);
          //         if (activityProductsItems.length == productCodes.length) {
          //           break;
          //         }
          //       }
          //     }
          //   }
          // }
          this.formItem.activityInfoRuleList.push(
            {
              index: this.formItem.activityInfoRuleList.length + 1,
              activityRuleRate: element.activityRuleRate + '',
              activityProducts: element.productList
            }
          );
        }
      }
    },
    // 设置满赠促销活动详情显示
    configRuleDiscountModalData(data) {
      this.formItem.activityName = data.activityName;
      this.formItem.activityMatchUserType = data.activityMatchUserType + '';
      this.formItem.activityChannelList = data.activityChannelList;
      this.formItem.activityDateType = data.activityDateType + '';
      this.formItem.activityMatchDayOfWeek = data.activityMatchDayOfWeek;
      this.formItem.activityTimeStart = data.activityTimeStart;
      this.formItem.activityTimeEnd = data.activityTimeEnd;
      this.formItem.orderRuleLimitStatus = data.orderRuleLimitStatus;
      this.formItem.productMultipartRuleLimitStatus = data.productMultipartRuleLimitStatus;
      this.formItem.activityDescription = data.activityDescription;

      if (data.activityDateType == '1') {
        // 自定义日期
        this.formItem.activityDateStart = data.activityDateStart;
        this.formItem.activityDateEnd = data.activityDateEnd;
        this.formItem.activityDateRange = [data.activityDateStart, data.activityDateEnd];
      }

      // 不可用日期
      this.formItem.invalidDateList = [];
      if (data.activityInfoMatchDateList && data.activityInfoMatchDateList.length > 0) {
        for (let i = 0; i < data.activityInfoMatchDateList.length; i++) {
          let dateItem = data.activityInfoMatchDateList[i];
          this.formItem.invalidDateList.push({
            dateOfStart: dateItem.dateOfStart,
            dateOfEnd: dateItem.dateOfEnd,
            dateRange: [dateItem.dateOfStart, dateItem.dateOfEnd]
          });
        }
      }

      // 活动星期
      this.transformDataToActivityDaysOfWeek(data.activityMatchDayOfWeek);

      // 活动规则
      if (data.activityInfoRuleVOList.length > 0) {
        // 满赠活动增长规则类型
        this.formItem.activityProductConditionIncreaseStatus = data.activityInfoRuleVOList[0].activityProductConditionIncreaseStatus + '';

        // 活动规则适用商品类型
        this.formItem.activityProductConditionType = data.activityInfoRuleVOList[0].activityProductConditionType + '';

        // 活动指定商品分类
        var activityProductClassConditionCodeListStr = data.activityInfoRuleVOList[0]['activityProductClassConditionCodeListStr'];
        if (activityProductClassConditionCodeListStr && activityProductClassConditionCodeListStr.length > 0) {
          var productClassCodes = activityProductClassConditionCodeListStr.split(',');
          var activityProductClassItems = [];
          // 在全部商品分类信息中查询商品分类信息
          if (productClassCodes.length > 0 && this.productCategoryOriginalData.length > 0) {
            for (let j = 0; j < productClassCodes.length; j++) {
              const classCode = productClassCodes[j];
              for (let k = 0; k < this.productCategoryOriginalData.length; k++) {
                const productClassItem = this.productCategoryOriginalData[k];
                if (productClassItem.classCode == classCode) {
                  activityProductClassItems.push(productClassItem);
                  if (activityProductClassItems.length == productClassCodes.length) {
                    break;
                  }
                }
              }
            }
            this.formItem.activityProductTypes = activityProductClassItems;
          }
        }
        // 活动指定商品
        var activityProductConditionCodeListStr = data.activityInfoRuleVOList[0]['activityProductConditionCodeListStr'];
        if (activityProductConditionCodeListStr && activityProductConditionCodeListStr.length > 0) {
          var productCodes = activityProductConditionCodeListStr.split(',');
          var activityProductsItems = [];
          // 在全部商品信息中查询商品信息
          if (productCodes.length > 0 && this.productTableCacheData['']) {
            for (let j = 0; j < productCodes.length; j++) {
              const productCode = productCodes[j];
              for (let k = 0; k < this.productTableCacheData[''].length; k++) {
                const productItem = this.productTableCacheData[''][k];
                if (productItem.productCode == productCode) {
                  activityProductsItems.push(productItem);
                  if (activityProductsItems.length == productCodes.length) {
                    break;
                  }
                }
              }
            }
            this.formItem.activityProducts = activityProductsItems;
          }

          this.formItem.activityProducts = data.activityInfoRuleVOList[0].productList;
        }

        // 优惠规则列表：仅商品折扣可设置多个，其余活动类型仅可设置1个
        if (data.activityInfoRuleVOList[0].activityInfoRuleProductGiveList && data.activityInfoRuleVOList[0].activityInfoRuleProductGiveList.length > 0) {
          this.formItem.activityInfoRuleProductGiveList = [];

          for (let i = 0; i < data.activityInfoRuleVOList[0].activityInfoRuleProductGiveList.length; i++) {
            var element = data.activityInfoRuleVOList[0].activityInfoRuleProductGiveList[i];
            // var productCodes = element.giveProductCodeListStr.split(',');
            // var giveProductList = [];
            // for (let j = 0; j < productCodes.length; j++) {
            //   const productCode = productCodes[j];

            // for (let k = 0; k < this.productTableCacheData[''].length; k++) {
            //   const productItem = this.productTableCacheData[''][k];
            //   if (productItem.productCode == productCode) {
            //     giveProductList.push(productItem);
            //     if (giveProductList.length == productCodes.length) {
            //       break;
            //     }
            //   }
            // }
            // }
            this.formItem.activityInfoRuleProductGiveList.push({
              giveProductList: element.productList,
              conditionAmount: element.conditionAmount,
              giveCount: element.giveCount
            });
          }
        }
      }
    },
    disappear() {
      this.closeModal();
    },
    // 设置门店列表数据
    configStoreListInfo() {
      var tempStoreListStr = JSON.stringify(this.storeList);
      if (tempStoreListStr.length < 1) { return; }
      var tempStoreList = JSON.parse(tempStoreListStr);
      for (var i = 0; i < tempStoreList.length; i++) {
        var item = tempStoreList[i];
        item['_checked'] = false;
        for (var j = 0; j < this.formItem.activeShopList.length; j++) {
          var selectedStoreItem = this.formItem.activeShopList[j];
          if (selectedStoreItem.storeCode == item.storeCode) {
            item['_checked'] = true;
          }
        }
      }
      this.storeList = tempStoreList;
    },
    // 设置默认时间范围
    setNormalDateRange() {
      let newTimeDate = new Date();
      this.normalDateRange = [
        Format(newTimeDate, "yy-MM-dd"),
        Format(newTimeDate, "yy-MM-dd")
      ];
      this.formItem.activityDateRange = this.normalDateRange;
      this.formItem.activityTimeOfDay = this.normalDateRange[0];
      this.formItem.activityTimeStart = "00:00:00";
      this.formItem.activityTimeEnd = "23:59:59";
    },
    // 重置创建促销活动模态窗数据
    resetModalData() {
      this.formItem.activityName = ""; // 活动名称
      this.formItem.activityMatchUserType = "0"; // 活动对象
      this.formItem.activeShopList = [];
      this.formItem.activityChannelPosType = true; // 活动渠道
      this.formItem.activityDateType = "0"; // 活动日期
      this.formItem.activityDateStart = this.normalDateRange[0]; // 自定义开始日期
      this.formItem.activityDateEnd = this.normalDateRange[1]; // 自定义结束日期
      this.formItem.invalidDateList = []; // 不可用日期列表
      this.formItem.activityTimeOfDay = ""; // 活动时间
      this.formItem.orderRuleLimitStatus = "0"; // 每单是否限购
      this.formItem.productMultipartRuleLimitStatus = "0"; // 同一商品
      this.formItem.activityInfoRuleList = [ // 商品折扣活动规则列表
        {
          index: 1,
          activityRuleRate: "", // 商品折扣活动规则折扣率
          activityProducts: [] // 商品折扣活动规则折扣商品
        }
      ];
      this.formItem.activityRuleRate = ""; // 整单折扣率
      this.formItem.activityProductTypes = []; // 活动商品类型
      this.formItem.activityProducts = []; // 活动商品(创建整单促销活动使用)
      this.formItem.productListOwnerRuleIndex = 0; // 添加商品时归属条件的下标（创建商品促销、创建满赠促销使用）
      this.formItem.activityProductConditionIncreaseStatus = "0"; // 优惠方式：满赠/每满赠
      this.formItem.mark = ""; // 活动说明
      this.formItem.isShowMoreSettings = false; // 是否显示更多设置
      this.formItem.isUnfoldMoreSettings = false; // 是否展开更多设置
      this.formItem.activityInfoRuleProductGiveList = [ // 优惠规则列表
        {
          conditionAmount: "", // 满多少
          giveCount: "", // 赠多少
          giveProductList: [] // 选择的赠送商品列表
        }
      ];
      this.formItem.activityProductConditionType = "0"; // 适用商品
      this.formItem.activityDescription = ""; // 活动说明
    },
    // 点击选择活动门店
    activityShopChoice() {
      this.showShopListModal = true;
      this.configStoreListInfo();
    },
    // 取消选择活动门店
    closeShopListModal() {
      this.showShopListModal = false;
    },
    // 门店列表选择门店
    shopListSelectedChange(items) {
      this.currentTempSelectedProductData = items;
    },
    // 门店列表弹窗点击重置
    handleShopSelectModalReset() {
      this.currentTempSelectedProductData = [];
      this.$refs.activityStoreListSelection.selectAll(false);
    },
    // 门店列表弹窗点击取消
    handleShopSelectModalCancel() {
      this.showShopListModal = false;
      this.currentTempSelectedProductData = [];
    },
    // 门店列表弹窗点击确定
    handleShopSelectModalSure() {
      if (this.currentTempSelectedProductData.length == 0) {
        this.$Message.info("请至少选中一家门店");
      } else {
        this.showShopListModal = false;
        this.formItem.activeShopList = this.currentTempSelectedProductData;
        this.currentTempSelectedProductData = [];
      }
    },
    // 关闭商品分类模态弹窗
    closeProductCategoryModal() {
      this.showProductCategoryModal = false;
    },
    // 清空商品分类选择
    handleProductCategoryModalReset() {
      this.productCategoryTreeData = this.productCategoryTreeOriginalData;
      this.currentSelectedProductCategoryTreeData = [];
    },
    // 商品分类模态弹窗点击取消
    handleProductCategoryModalCancel() {
      this.closeProductCategoryModal();
    },
    // 商品分类模态弹窗点击确定
    handleProductCategoryModalSubmit() {
      this.showProductCategoryModal = false;
      this.formItem.activityProductTypes = this.currentSelectedProductCategoryTreeData;
    },
    // 关闭选择商品模态窗
    closeProductListModal() {
      this.showProductListModal = false;
    },
    // 清空商品列表选择
    handleProductSelectModalReset() {
      this.currentTempSelectedProductData = [];

      // 重新加载商品列表数据
      let lastCacheData = this.productTableCacheData[this.classCode];
      if (lastCacheData) {
        this.productTableData = lastCacheData;
      }
    },
    // 商品列表模态弹窗点击取消
    handleProductSelectModalCancel() {
      this.closeProductListModal();
    },
    // 商品列表模态弹窗点击确定
    handleProductSelectModalSure() {
      this.showProductListModal = false;
      if (this.formItem.productListOwnerRuleIndex == -1) {
        // 指定商品
        this.formItem.activityProducts = this.currentTempSelectedProductData;
      } else {
        if (this.type == 1 || this.type == 7) {
          this.formItem.activityInfoRuleList[this.formItem.productListOwnerRuleIndex].activityProducts = this.currentTempSelectedProductData;
          this.$refs.productDiscountFormItem.validateField('activityInfoRuleList.' + this.formItem.productListOwnerRuleIndex + '.activityProducts');
        } else if (this.type == 2 || this.type == 8) {
          this.formItem.activityInfoRuleProductGiveList[this.formItem.productListOwnerRuleIndex].giveProductList = this.currentTempSelectedProductData;
          this.$refs.ruleDiscountFormItem.validateField('activityInfoRuleProductGive' + this.formItem.productListOwnerRuleIndex);
        }
      }
    },
    // 限购规则状态修改
    handleOrderRuleLimitStatusChange(status) {
      if (status == '1') {
        setTimeout(() => {
          this.costomUnitOfInputViewStyle();
        }, 10);
      }
    },
    // 自定义日期更改
    handleCustomDateChange(daterange) {
      this.formItem.activityDateRange = daterange;
      this.formItem.activityDateStart = daterange[0];
      this.formItem.activityDateEnd = daterange[1];
    },
    // 不可用日期更改
    handleCustomDisableDateChange(daterange, index) {
      this.formItem.invalidDateList[index]['dateOfStart'] = daterange[0];
      this.formItem.invalidDateList[index]['dateOfEnd'] = daterange[1];
      this.formItem.invalidDateList[index]['dateRange'] = daterange;
    },
    // 活动日期全选修改
    handleCheckActivityDaysOfWeekAll() {
      if (this.activityDaysOfWeekIndeterminate) {
        this.checkActivityDaysOfWeekAll = false;
      } else {
        this.checkActivityDaysOfWeekAll = !this.checkActivityDaysOfWeekAll;
      }
      this.activityDaysOfWeekIndeterminate = false;

      if (this.checkActivityDaysOfWeekAll) {
        this.checkActivityDaysOfWeekAllGroup = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'];
        this.formItem.activityMatchDayOfWeek = "0,1,2,3,4,5,6";
      } else {
        this.checkActivityDaysOfWeekAllGroup = [];
        this.formItem.activityMatchDayOfWeek = null;
      }
    },
    // 活动日期修改
    handleCheckActivityDaysOfWeekAllGroupChange(data) {
      if (data.length === 7) {
        this.activityDaysOfWeekIndeterminate = false;
        this.checkActivityDaysOfWeekAll = true;
        this.formItem.activityMatchDayOfWeek = "0,1,2,3,4,5,6";
      } else if (data.length > 0) {
        this.activityDaysOfWeekIndeterminate = true;
        this.checkActivityDaysOfWeekAll = false;
        this.formItem.activityMatchDayOfWeek = this.transformActivityDaysOfWeekToParams(data);
      } else {
        this.activityDaysOfWeekIndeterminate = false;
        this.checkActivityDaysOfWeekAll = false;
        this.formItem.activityMatchDayOfWeek = null;
      }
    },
    // 转换活动星期为接口参数
    transformActivityDaysOfWeekToParams(data) {
      let tempWeekStr = "";
      for (var index = 0; index < data.length; index++) {
        let value = data[index];
        if (value == '星期一') {
          tempWeekStr = tempWeekStr.length > 0 ? tempWeekStr + ',1' : '1';
        } else if (value == '星期二') {
          tempWeekStr = tempWeekStr.length > 0 ? tempWeekStr + ',2' : '2';
        } else if (value == '星期三') {
          tempWeekStr = tempWeekStr.length > 0 ? tempWeekStr + ',3' : '3';
        } else if (value == '星期四') {
          tempWeekStr = tempWeekStr.length > 0 ? tempWeekStr + ',4' : '4';
        } else if (value == '星期五') {
          tempWeekStr = tempWeekStr.length > 0 ? tempWeekStr + ',5' : '5';
        } else if (value == '星期六') {
          tempWeekStr = tempWeekStr.length > 0 ? tempWeekStr + ',6' : '6';
        } else if (value == '星期日') {
          tempWeekStr = tempWeekStr.length > 0 ? tempWeekStr + ',0' : '0';
        }
      }
      return tempWeekStr;
    },
    // 转换接口返回数据为活动星期数据
    transformDataToActivityDaysOfWeek(activityMatchDayOfWeek) {
      if (!activityMatchDayOfWeek || activityMatchDayOfWeek.length < 1) {
        this.checkActivityDaysOfWeekAllGroup = [];
        this.formItem.activityMatchDayOfWeek = null;
      } else {
        let array = activityMatchDayOfWeek.split(',');
        var tempWeekOfDays = [];
        for (var index = 0; index < array.length; index++) {
          let value = array[index];
          if (value == '1') {
            tempWeekOfDays.push('星期一');
          } else if (value == '2') {
            tempWeekOfDays.push('星期二');
          } else if (value == '3') {
            tempWeekOfDays.push('星期三');
          } else if (value == '4') {
            tempWeekOfDays.push('星期四');
          } else if (value == '5') {
            tempWeekOfDays.push('星期五');
          } else if (value == '6') {
            tempWeekOfDays.push('星期六');
          } else if (value == '0') {
            tempWeekOfDays.push('星期日');
          }
        }
        this.checkActivityDaysOfWeekAllGroup = tempWeekOfDays;
        this.formItem.activityMatchDayOfWeek = activityMatchDayOfWeek;
      }
    },
    // 点击展开更多设置
    handleUnfoldMoreSettings() {
      this.formItem.isUnfoldMoreSettings = !this.formItem.isUnfoldMoreSettings;
    },
    // 添加不可用日期段
    handleAddDisableDateRange() {
      this.formItem.invalidDateList.push(
        {
          id: generateRandom(),
          dateRange: this.normalDateRange,
          dateOfStart: this.normalDateRange[0],
          dateOfEnd: this.normalDateRange[1]
        }
      );
    },
    // 删除选择的门店
    handleDeleteSelectedActivityShop(index) {
      this.formItem.activeShopList.splice(index, 1);
    },
    // 点击删除不可用日期段
    handleDeleteDisableDatePicker(index) {
      this.formItem.invalidDateList.splice(index, 1);
    },
    // 点击删除规则列表
    handleDeleteInfoRuleList(index) {
      this.formItem.activityInfoRuleList.splice(index, 1);
    },
    // 活动开始时间更改
    handleActivityTimeStartChange(time) {
      this.formItem.activityTimeStart = time;
    },
    // 活动结束时间更改
    handleActivityTimeEndChange(time) {
      this.formItem.activityTimeEnd = time;
    },
    // 添加商品促销活动规则
    handleAddDiscountRuleOfProduct() {
      this.formItem.activityInfoRuleList.push(
        {
          index: this.formItem.activityInfoRuleList.length + 1,
          activityRuleRate: "",
          activityProducts: []
        }
      );

      setTimeout(() => {
        this.costomUnitOfInputViewStyle();
      }, 10);
    },
    // 添加优惠条件
    handleAddPreferentialConditionsItem() {
      this.formItem.activityInfoRuleProductGiveList.push({
        conditionAmount: "", // 满多少
        giveCount: "", // 赠多少
        giveProductList: [] // 选择的赠送商品列表
      });

      setTimeout(() => {
        this.costomUnitOfInputViewStyle();
      }, 10);
    },
    // 删除优惠条件
    handleDeletePreferentialConditionsItem(index) {
      this.formItem.activityInfoRuleProductGiveList.splice(index, 1);
    },
    // 活动规则-选择分类模态窗打开
    activityProductTargetCategoryChoice() {
      this.showProductCategoryModal = true;
      if (this.productCategoryTreeData.length == 0) {
        const Loading = this.$myLoading({
          content: "正在查询商品，请稍后…"
        });
        Promise.all([this.productClassFindList()]).then((result) => {
          this.displaySelectedProductTypes();
          this.closeLoading(Loading);
        });
      } else {
        this.displaySelectedProductTypes();
      }
    },
    // 设置商品分类已选择的回显出来
    displaySelectedProductTypes() {
      if (this.formItem.activityProductTypes.length > 0) {
        var tempProductCategoryTreeDataStr = JSON.stringify(this.productCategoryTreeData);
        if (tempProductCategoryTreeDataStr.length < 1) { return; }
        var tempProductCategoryTreeData = JSON.parse(tempProductCategoryTreeDataStr);
        for (var i = 0; i < tempProductCategoryTreeData.length; i++) {
          var item = tempProductCategoryTreeData[i];
          item['_checked'] = false;
          item.checked = false;
          for (var j = 0; j < this.formItem.activityProductTypes.length; j++) {
            var selectedProductCategoryItem = this.formItem.activityProductTypes[j];
            if (selectedProductCategoryItem.classCode == item.classCode) {
              item['_checked'] = true;
              item.checked = true;
            }
          }
        }
        this.productCategoryTreeData = tempProductCategoryTreeData;
      }
    },
    // 活动规则-选择分类模态窗口关闭
    closeProductCategoryModal() {
      this.showProductCategoryModal = false;
    },
    // 删除活动指定商品分类
    deleteSelectedActivityProductTargetCategory(index) {
      this.formItem.activityProductTypes.splice(index, 1);
    },
    // 删除活动指定商品
    deleteSelectedActivityProduct(index) {
      this.formItem.activityProducts.splice(index, 1);
    },
    // 删除规则条件下的活动指定商品
    deleteSelectedActivityRuleProduct(ruleIndex, productIndex) {
      if (this.type == 1 || this.type == 7) {
        this.formItem.activityInfoRuleList[ruleIndex].activityProducts.splice(productIndex, 1);
      } else if (this.type == 2 || this.type == 8) {
        this.formItem.activityInfoRuleProductGiveList[ruleIndex].giveProductList.splice(productIndex, 1);
      }
    },
    // 商品分类树状图选中节点多选窗
    productCategoryTreeSelcted(treeNode) {
      this.currentSelectedProductCategoryTreeData = treeNode;
    },
    // 商品分类树状图选中节点
    productSelectTreeSelcted(treeNode) {
      if (treeNode.length == 0) {
        this.currentTreeNode[0].selected = true;
      } else {
        this.classCode = treeNode[0].classCode;
        let products = this.productTableCacheData[this.classCode];
        if (products && products.length > 0) {
          this.setProductListTableSelectedData();
        } else {
          this.currentTreeNode = treeNode;
          this.pid = treeNode[0].pid;
          this.fastQuery = "";
          const Loading = this.$myLoading({
            content: "正在查询商品，请稍后…"
          });
          Promise.all([this.productFindPage()]).then((result) => {
            this.setProductListTableSelectedData();
            this.closeLoading(Loading);
          });
        }
      }
    },
    // 活动规则-选择商品
    activityProductChoice(index) {
      this.formItem.productListOwnerRuleIndex = index;
      this.showProductListModal = true;

      // 加载商品分类树状图数据
      if (this.productCategoryTreeData.length == 0) {
        const Loading = this.$myLoading({
          content: "正在查询商品，请稍后…"
        });
        Promise.all([this.productClassFindList()]).then((result) => {
          this.closeLoading(Loading);
        });
      }

      // 加载商品列表数据
      let productListCacheData = this.productTableCacheData[this.classCode];
      if (productListCacheData) {
        this.setProductListTableSelectedData();
      } else {
        const Loading = this.$myLoading({
          content: "正在查询商品，请稍后…"
        });
        Promise.all([this.productFindPage()]).then((result) => {
          this.setProductListTableSelectedData();
          this.closeLoading(Loading);
        });
      }
    },
    setListCheckedStatus(selectedList) {
      let productListCacheData = this.productTableCacheData[this.classCode];
      if (productListCacheData.length < 1) {
        return [];
      }

      let tempProductTableData = JSON.stringify(productListCacheData);
      if (tempProductTableData.length < 1) { return []; }
      tempProductTableData = JSON.parse(tempProductTableData);
      if (!selectedList || selectedList.length == 0) { return tempProductTableData; }

      tempProductTableData.map((item) => {
        selectedList.map((selectedItem) => {
          if (item.productCode == selectedItem.productCode) {
            item['_checked'] = true;
          }
        })
      });
      return tempProductTableData;
    },
    // 商品列表显示已选中的商品
    setProductListTableSelectedData() {
      if (this.type == 0 || this.type == 6) {
        // 创建整单促销活动
        this.productTableData = this.setListCheckedStatus(this.formItem.activityProducts);
      } else if (this.type == 1 || this.type == 7) {
        // 创建商品促销活动
        if (this.formItem.productListOwnerRuleIndex == -1) {
          this.productTableData = this.setListCheckedStatus(this.formItem.activityProducts);
        } else {
          var tempProductTableData = this.setListCheckedStatus(this.formItem.activityInfoRuleList[this.formItem.productListOwnerRuleIndex].activityProducts);
          // 禁用其他规则下的商品选择
          for (let i = 0; i < tempProductTableData.length; i++) {
            let tempProduct = tempProductTableData[i];
            tempProduct['_disabled'] = false;

            for (let j = 0; j < this.formItem.activityInfoRuleList.length; j++) {
              let rule = this.formItem.activityInfoRuleList[j];
              if (j !== this.formItem.productListOwnerRuleIndex) {
                for (let k = 0; k < rule.activityProducts.length; k++) {
                  let otherRuleProduct = rule.activityProducts[k];
                  if (otherRuleProduct.productCode == tempProduct.productCode) {
                    tempProduct['_disabled'] = true;
                  }
                }
              }
            }
          }
          this.productTableData = tempProductTableData;
        }
      } else if (this.type == 2 || this.type == 8) {
        // 创建满赠/每满赠促销活动
        if (this.formItem.productListOwnerRuleIndex == -1) {
          this.productTableData = this.setListCheckedStatus(this.formItem.activityProducts);
        } else {
          var tempProductTableData = this.setListCheckedStatus(this.formItem.activityInfoRuleProductGiveList[this.formItem.productListOwnerRuleIndex].giveProductList);
          this.productTableData = tempProductTableData;
        }
      }
    },
    // 商品列表选择回调
    productListSelectedChange(items) {
      this.currentTempSelectedProductData = items;
    },
    // 活动详情
    activityManageDetail() {
      const Loading = this.$myLoading();
      let promiseList = [];
      // 全部商品分类
      promiseList.push(this.productClassFindList());
      // 全部商品
      promiseList.push(this.productFindPage());

      if (this.accountType == 'store') {
        // 单店详情
        promiseList.push(this.storeActivityManageDetail());
        // 合并请求
        Promise.all(promiseList).then((result) => {
          if (result && result.length > 1 && result[2]) {
            this.configActivityDetailData(result[2]);
          }
          this.closeLoading(Loading);
        });
      } else {
        // 连锁详情
        promiseList.push(this.chainActivityManageDetail());
        promiseList.push(this.queryBranchStoreList());
        // 合并请求
        Promise.all(promiseList).then((result) => {
          if (result && result.length > 1 && result[2]) {
            this.storeList = result[3];
            this.configActivityDetailData(result[2]);
            this.configStoreListInfo();
          }
          this.closeLoading(Loading);
        });
      }
    },
    // 已绑定门店列表
    queryBranchStoreList() {
      let _this = this;
      return new Promise((resolve, reject) => {
        chainQueryBindStoreList('').then((result) => {
          if (result.data.code == 200 && result.status == 200) {
            resolve(result.data.data);
          } else {
            _this.$Message.error(result.data.message);
            resolve(false);
          }
        })
      })
    },
    // 查看单店促销活动详情
    storeActivityManageDetail() {
      let _this = this;
      return new Promise((resolve, reject) => {
        storeActivityManageDetail({
          activityId: this.formItem.activityId
        }).then((result) => {
          if (result.data.code == 200 && result.status == 200) {
            resolve(result.data.data);
          } else {
            _this.$Message.error(result.data.message);
            resolve(false);
          }
        })
      })
    },
    // 查看连锁促销活动详情
    chainActivityManageDetail() {
      let _this = this;
      return new Promise((resolve, reject) => {
        chainActivityManageDetail({
          activityId: this.formItem.activityId
        }).then((result) => {
          if (result.status == 200 && result.data.code == 200) {
            resolve(result.data.data);
          } else {
            _this.$Message.error(result.data.message);
            resolve(false);
          }
        })
      })
    },
    // 请求商品分类
    productClassFindList() {
      let fastQuery = this.fastQuery;
      let page = 0;
      let pageSize = 0;
      let storeCode = this.storeCode;
      let pid = '';
      let _this = this;
      return new Promise((resolve, reject) => {
        productClassFindList({
          fastQuery,
          page,
          pageSize,
          storeCode,
          pid
        }).then((result) => {
          if (result.data.code == 200 && result.status == 200) {
            let treeUpdateList = buildTree(result.data.data, null);
            _this.productCategoryOriginalData = result.data.data;
            _this.productCategoryTreeOriginalData = JSON.parse(JSON.stringify(treeUpdateList));
            _this.productCategoryTreeData = treeUpdateList;
            resolve(true);
          } else {
            resolve(false);
          }
        })
      })
    },
    // 请求商品列表
    productFindPage(Loading) {
      let classCode = this.classCode;
      let page = this.pageNum;
      let pageSize = this.pageSize;
      let fastQuery = this.fastQuery;
      let storeCode = this.storeCode;
      let _this = this;
      return new Promise((resolve, reject) => {
        productFindPage({
          classCode,
          page,
          pageSize,
          fastQuery,
          storeCode
        }).then((result) => {
          if (result.data.code == 200 && result.status == 200) {
            _this.productTableCacheData[classCode] = result.data.data.list;
            resolve(true);
          } else {
            resolve(false);
          }
        })
      });
    },
    // 检查创建促销活动参数
    checkCreateSellPromotionRequestParams() {
      if (!this.formItem.activityName || this.formItem.activityName.length < 1) {
        this.$Message.error('活动名称不能为空');
        return false;
      }

      if (this.accountType == 'company') {
        if (!this.formItem.activeShopList || this.formItem.activeShopList.length < 1) {
          this.$Message.error('活动门店不能为空');
          return false;
        }
      }

      if (!this.formItem.activityMatchDayOfWeek || this.formItem.activityMatchDayOfWeek.length < 1) {
        this.$Message.error('活动星期不能为空');
        return false;
      }

      if (this.type == 0) {
        if (!this.formItem.activityRuleRate || this.formItem.activityRuleRate.length < 1) {
          this.$Message.error('整单折扣率不能为空');
          return false;
        }
      } else if (this.type == 1 || this.type == 7) {
        if (this.formItem.orderRuleLimitStatus == '1' && (!this.formItem.orderRuleLimitCount || this.formItem.orderRuleLimitCount == '')) {
          // 每单限购数量
          this.$Message.error('每单限购数量不能为空');
          return false;
        }

        if (this.formItem.productMultipartRuleLimitStatus == '1' && (!this.formItem.productMultipartRuleLimitCount || this.formItem.productMultipartRuleLimitCount == '')) {
          // 同一商品限购数量
          this.$Message.error('同一商品限购数量不能为空');
          return false;
        }

        if (this.formItem.orderRuleLimitStatus == '1' && this.formItem.productMultipartRuleLimitStatus == '1') {
          if (parseInt(this.formItem.orderRuleLimitCount) < parseInt(this.formItem.productMultipartRuleLimitCount)) {
            this.$Message.error('同一商品限购数量不能大于每单限购数量');
            return false;
          }
        }

        for (var i = 0; i < this.formItem.activityInfoRuleList.length; i++) {
          let rule = this.formItem.activityInfoRuleList[i];

          if (!rule.activityRuleRate || rule.activityRuleRate.length < 1) {
            this.$Message.error('活动折扣率不能为空');
            return false;
          }
          if (!rule.activityProducts || rule.activityProducts.length < 1) {
            this.$Message.error('活动商品不能为空');
            return false;
          }
        }
      } else if (this.type == 2 || this.type == 8) {
        for (var i = 0; i < this.formItem.activityInfoRuleProductGiveList.length; i++) {
          // 优惠条件规则列表
          let rule = this.formItem.activityInfoRuleProductGiveList[i];
          if (!rule.conditionAmount || rule.conditionAmount.length < 1) {
            this.$Message.error('满赠规则触发金额不能为空');
            return false;
          }

          if (!rule.giveCount || rule.giveCount.length < 1) {
            this.$Message.error('赠送数量不能为空');
            return false;
          }

          if (!rule.giveProductList || rule.giveProductList.length < 1) {
            this.$Message.error('赠送商品列表不能为空');
            return false;
          }
        }
      }

      return true;
    },
    // 获取创建促销活动请求参数
    getCreateSellPromotionRequestParams() {
      if (this.type == 0 || this.type == 6) {
        // 创建/更新整单促销活动请求参数
        var params = {
          activityType: 0,
          activityName: this.formItem.activityName,
          activityCreateSource: this.accountType == 'store' ? '0' : '1',
          activityMatchUserType: this.formItem.activityMatchUserType,
          activityChannelList: '0',
          activityDateType: this.formItem.activityDateType,
          activityMatchDayOfWeek: this.formItem.activityMatchDayOfWeek,
          activityTimeStart: this.formItem.activityTimeStart,
          activityTimeEnd: this.formItem.activityTimeEnd,
          activityDescription: this.formItem.activityDescription
        };

        if (this.formItem.activityId && this.formItem.activityId !== '') {
          params['id'] = this.formItem.activityId;
        }

        if (this.accountType == 'company') {
          var activeShopCodeList = [];
          for (let i = 0; i < this.formItem.activeShopList.length; i++) {
            const item = this.formItem.activeShopList[i];
            activeShopCodeList.push(item.storeCode);
          }
          params['activeShopCodeList'] = activeShopCodeList;
        }

        if (this.formItem.activityDateType == '1') {
          // 自定义日期
          params['activityDateStart'] = this.formItem.activityDateRange[0];
          params['activityDateEnd'] = this.formItem.activityDateRange[1];
        }

        if (this.formItem.invalidDateList.length > 0) {
          // 不可用日期列表
          var invalidDateList = [];
          for (var i = 0; i < this.formItem.invalidDateList.length; i++) {
            var element = this.formItem.invalidDateList[i];
            invalidDateList.push(
              {
                dateOfStart: element.dateOfStart,
                dateOfEnd: element.dateOfEnd
              }
            );
          }
          params['invalidDateList'] = invalidDateList;
        }

        // 活动规则
        var activityInfoRuleList = [
          {
            activityRuleRate: this.formItem.activityRuleRate,
            activityProductConditionType: this.formItem.activityProductConditionType
          }
        ];

        if (this.formItem.activityProductTypes.length > 0) {
          // 活动指定商品分类
          var activityProductClassConditionCodeListStr = this.formItem.activityProductTypes[0].classCode;
          for (var i = 1; i < this.formItem.activityProductTypes.length; i++) {
            let element = this.formItem.activityProductTypes[i];
            activityProductClassConditionCodeListStr = activityProductClassConditionCodeListStr + ',' + element.classCode;
          }
          activityInfoRuleList[0]['activityProductClassConditionCodeListStr'] = activityProductClassConditionCodeListStr;
        }
        if (this.formItem.activityProducts.length > 0) {
          // 活动指定商品
          var activityProductConditionCodeListStr = this.formItem.activityProducts[0].productCode;
          for (var i = 1; i < this.formItem.activityProducts.length; i++) {
            var element = this.formItem.activityProducts[i];
            activityProductConditionCodeListStr = activityProductConditionCodeListStr + ',' + element.productCode;
          }
          activityInfoRuleList[0]['activityProductConditionCodeListStr'] = activityProductConditionCodeListStr;
        }

        params['activityInfoRuleList'] = activityInfoRuleList;
        return params;
      } else if (this.type == 1 || this.type == 7) {
        // 创建/更新商品折扣促销活动请求参数
        var params = {
          activityType: 1,
          activityName: this.formItem.activityName,
          activityCreateSource: this.accountType == 'store' ? '0' : '1',
          activityMatchUserType: this.formItem.activityMatchUserType,
          activityChannelList: '0',
          activityDateType: this.formItem.activityDateType,
          activityMatchDayOfWeek: this.formItem.activityMatchDayOfWeek,
          activityTimeStart: this.formItem.activityTimeStart,
          activityTimeEnd: this.formItem.activityTimeEnd,
          orderRuleLimitStatus: this.formItem.orderRuleLimitStatus,
          productMultipartRuleLimitStatus: this.formItem.productMultipartRuleLimitStatus,
          activityDescription: this.formItem.activityDescription
        };

        if (this.formItem.activityId && this.formItem.activityId !== '') {
          params['id'] = this.formItem.activityId;
        }

        if (this.accountType == 'company') {
          var activeShopCodeList = [];
          for (let i = 0; i < this.formItem.activeShopList.length; i++) {
            const item = this.formItem.activeShopList[i];
            activeShopCodeList.push(item.storeCode);
          }
          params['activeShopCodeList'] = activeShopCodeList;
        }

        if (this.formItem.activityDateType == '1') {
          // 自定义日期
          params['activityDateStart'] = this.formItem.activityDateRange[0];
          params['activityDateEnd'] = this.formItem.activityDateRange[1];
        }

        if (this.formItem.invalidDateList.length > 0) {
          // 不可用日期列表
          var invalidDateList = [];
          for (var i = 0; i < this.formItem.invalidDateList.length; i++) {
            var element = this.formItem.invalidDateList[i];
            invalidDateList.push(
              {
                dateOfStart: element.dateOfStart,
                dateOfEnd: element.dateOfEnd
              }
            );
          }
          params['invalidDateList'] = invalidDateList;
        }

        if (this.formItem.orderRuleLimitStatus == '1') {
          // 每单限购数量
          params['orderRuleLimitCount'] = this.formItem.orderRuleLimitCount;
        }

        if (this.formItem.productMultipartRuleLimitStatus == '1') {
          // 同一商品限购数量
          params['productMultipartRuleLimitCount'] = this.formItem.productMultipartRuleLimitCount;
        }

        // 活动规则列表
        var activityInfoRuleList = [];
        for (var i = 0; i < this.formItem.activityInfoRuleList.length; i++) {
          var rule = this.formItem.activityInfoRuleList[i];
          var productConditionCodeListStr = rule.activityProducts[0].productCode;
          for (var j = 1; j < rule.activityProducts.length; j++) {
            var product = rule.activityProducts[j];
            productConditionCodeListStr = productConditionCodeListStr + ',' + product.productCode;
          }
          activityInfoRuleList.push(
            {
              activityRuleRate: rule.activityRuleRate,
              activityProductConditionCodeListStr: productConditionCodeListStr
            }
          );
        }
        params['activityInfoRuleList'] = activityInfoRuleList;
        return params;
      } else if (this.type == 2 || this.type == 8) {
        // 创建/更新满赠/每满赠促销活动请求参数
        var params = {
          activityType: 2,
          activityName: this.formItem.activityName,
          activityCreateSource: this.accountType == 'store' ? '0' : '1',
          activityMatchUserType: this.formItem.activityMatchUserType,
          activityChannelList: '0',
          activityDateType: this.formItem.activityDateType,
          activityMatchDayOfWeek: this.formItem.activityMatchDayOfWeek,
          activityTimeStart: this.formItem.activityTimeStart,
          activityTimeEnd: this.formItem.activityTimeEnd,
          activityDescription: this.formItem.activityDescription
        };

        if (this.formItem.activityId && this.formItem.activityId !== '') {
          params['id'] = this.formItem.activityId;
        }

        if (this.accountType == 'company') {
          var activeShopCodeList = [];
          for (let i = 0; i < this.formItem.activeShopList.length; i++) {
            const item = this.formItem.activeShopList[i];
            activeShopCodeList.push(item.storeCode);
          }
          params['activeShopCodeList'] = activeShopCodeList;
        }

        if (this.formItem.activityDateType == '1') {
          // 自定义日期
          params['activityDateStart'] = this.formItem.activityDateRange[0];
          params['activityDateEnd'] = this.formItem.activityDateRange[1];
        }

        if (this.formItem.invalidDateList.length > 0) {
          // 不可用日期列表
          var invalidDateList = [];
          for (var i = 0; i < this.formItem.invalidDateList.length; i++) {
            var element = this.formItem.invalidDateList[i];
            invalidDateList.push(
              {
                dateOfStart: element.dateOfStart,
                dateOfEnd: element.dateOfEnd
              }
            );
          }
          params['invalidDateList'] = invalidDateList;
        }

        // 活动规则列表
        var activityInfoRuleList = [];
        var activityInfoRuleProductGiveList = [];

        var activityProductClassConditionCodeListStr = '';
        if (this.formItem.activityProductTypes.length > 0) {
          // 活动指定商品分类
          activityProductClassConditionCodeListStr = this.formItem.activityProductTypes[0].classCode;
          for (var i = 1; i < this.formItem.activityProductTypes.length; i++) {
            var element = this.formItem.activityProductTypes[i];
            activityProductClassConditionCodeListStr = activityProductClassConditionCodeListStr + ',' + element.classCode;
          }
        }
        var activityProductConditionCodeListStr = '';
        if (this.formItem.activityProducts.length > 0) {
          // 活动指定商品
          activityProductConditionCodeListStr = this.formItem.activityProducts[0].productCode;
          for (var i = 1; i < this.formItem.activityProducts.length; i++) {
            var element = this.formItem.activityProducts[i];
            activityProductConditionCodeListStr = activityProductConditionCodeListStr + ',' + element.productCode;
          }
        }

        for (var i = 0; i < this.formItem.activityInfoRuleProductGiveList.length; i++) {
          var rule = this.formItem.activityInfoRuleProductGiveList[i];
          var productConditionCodeListStr = rule.giveProductList[0].productCode;
          for (var j = 1; j < rule.giveProductList.length; j++) {
            let product = rule.giveProductList[j];
            productConditionCodeListStr = productConditionCodeListStr + ',' + product.productCode;
          }
          activityInfoRuleProductGiveList.push(
            {
              conditionAmount: rule.conditionAmount,
              giveCount: rule.giveCount,
              giveProductCodeListStr: productConditionCodeListStr
            }
          );
        }

        // 活动规则：仅商品折扣可设置多个，其余活动类型仅可设置1个
        activityInfoRuleList.push(
          {
            activityProductClassConditionCodeListStr: activityProductClassConditionCodeListStr,
            activityProductConditionCodeListStr: activityProductConditionCodeListStr,
            activityProductConditionIncreaseStatus: this.formItem.activityProductConditionIncreaseStatus,
            activityProductConditionType: this.formItem.activityProductConditionType,
            activityInfoRuleProductGiveList: activityInfoRuleProductGiveList
          }
        );

        params['activityInfoRuleList'] = activityInfoRuleList;
        return params;
      }
    },
    // 关闭创建促销活动模态窗
    closeModal() {
      if (this.$refs.hasOwnProperty("orderDiscountFormItem")) {
        this.$refs["orderDiscountFormItem"].resetFields();
      }
      if (this.$refs.hasOwnProperty("productDiscountFormItem")) {
        this.$refs["productDiscountFormItem"].resetFields();
      }
      if (this.$refs.hasOwnProperty("ruleDiscountFormItem")) {
        this.$refs["ruleDiscountFormItem"].resetFields();
      }
      if (this.$refs.hasOwnProperty("activityStoreListSelection")) {
        this.$refs["activityStoreListSelection"].selectAll(false);
      }

      // 清空商品分类选择数据
      this.handleProductCategoryModalReset();
      // 清空商品选择数据
      this.handleProductSelectModalReset();
      // 清空每单限购数量
      this.formItem.orderRuleLimitCount = "0";
      // 清空同一商品限购数量
      this.formItem.productMultipartRuleLimitCount = "0";

      this.resetModalData();
      if (this.type == 0 || this.type == 3 || this.type == 6) {
        this.showOrderDiscountModal = false;
      }
      if (this.type == 1 || this.type == 4 || this.type == 7) {
        this.showProductDiscountModal = false;
      }
      if (this.type == 2 || this.type == 5 || this.type == 8) {
        this.showRuleDiscountModal = false;
      }
    },
    // 关闭创建促销活动模态窗回调
    handleCancel() {
      this.showCancelPrompt = true;
    },
    handleCancelSure() {
      this.showCancelPrompt = false;
      this.closeModal();
    },
    // 提交创建促销活动
    handleSubmit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          let checkParamsResult = this.checkCreateSellPromotionRequestParams();
          if (!checkParamsResult) {
            return;
          }
          let params = this.getCreateSellPromotionRequestParams();
          this.$emit("submit", params);
        } else {
          this.$Message.error('请按照提示修改后提交');
        }
      })
    },
    // 关闭加载动画
    closeLoading(Loading) {
      let timer = setTimeout(() => {
        clearTimeout(timer);
        timer = null;
        Loading && Loading.close();
      }, 300);
    }
  }
}
</script>
<style lang="less">
.ivu-checkbox-group {
  display: inline-block;
  margin-left: 7px;
}
.disable {
  color: #ccc;
  background-color: #f3f3f3;
  border: 1px #ccc solid !important;
}
.more-settings {
  display: flex;
  align-items: center;
  margin: 0 0 15px 100px;
}
.more-settings-text {
  color: #F8B009;
  font-size: 13px;
}
.more-settings-icon {
  width: 15px;
  height: 15px;
}
.disable-date-values {
  margin-top: 0px !important;
  display: block;
}
.disable-date-add {
  display: flex;
  flex-direction: column;
}
.disable-date-add-text {
  display: inline-flex;
  width: 100px;
  height: 21px;
  color: #F8B009;
  font-size: 13px;
}
.disable-date-add-tip {
  color: darkgray;
  font-size: 13px;
}
.disable-date-picker-delete {
  padding: 5px 0px 6px;
  margin-left: 10px;
  width: 50px;
}
.activity-time-separation-text {
  margin: 0 10px;
}
.activity-shop-desc {
  color: #F8B009;
  font-size: 13px;
}
.activity-product-target-category {
  display: flex;
  flex-direction: column;
  background-color: #f5f5f5;
}
.activity-product-target-category-text {
  display: flex;
  flex-direction: row;
  align-items: center;
  min-height: 50px;
}
.activity-product-target-category-text-title {
  font-size: 12px;
  margin-left: 55px;
}
.activity-product-target-category-text-add {
  color: #F8B009;
  font-size: 13px;
  height: 34px;
  padding-top: 2px;
}
.discount-rule-of-product-add {
  color: #F8B009;
  margin: 10px 0 13px 10px;
}
.activity-product-target-category-text-desc {
  color: darkgray;
  font-size: 12px;
}
.product-discount-list {
  margin-left: 0px !important;
  border: 0.5px solid #f5f5f5;
}
.activity-product-target-category-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-content:flex-start;
  max-height: 80px;
  margin: 0 30px 15px 0px;
  background-color: #fff;
  overflow: auto;
}
.activity-product-target-category-list-cell {
  display: flex;
  flex-direction: row;
  height: 30px;
  align-items: center;
  border: 1px #f5f5f5 solid;
  border-radius: 5px;
  margin: 5px 5px 5px 5px;
}
.activity-product-target-category-list-cell-text-disable {
  font-size: 13px;
  margin: 3px 10px;
}
.activity-product-target-category-list-cell-text {
  font-size: 13px;
  margin: 3px 0 3px 10px;
}
.activity-product-target-category-list-cell-space {
  margin: 0 5px 2px 5px;
}
.activity-product-target-category-list-cell-img {
  width: 13px;
  height: 13px;
  margin: 0 5px 2px 5px;
}
.activity-product-target {
  display: flex;
  flex-direction: column;
  background-color: #f5f5f5;
  margin-top: 10px;
}
.product-select-modal-content {
  display: flex;
}
.product-select-tree {
  max-height: 300px;
  overflow: auto;
}
.preferential-conditions-list-item {
  display: flex;
  flex-direction: column;
}
.preferential-conditions-list-more-item {
  display: flex;
  flex-direction: column;
  margin-top: 10px;
}
.preferential-conditions-list-item-row {
  display: flex;
  flex-direction: row;
}
.preferential-conditions-list-item-present-row {
  display: flex;
  flex-direction: row;
  margin-top: 10px;
}
.preferential-conditions-list-item-default-text {
  color: #172735;
  font-size: 13px;
}
.preferential-conditions-list-item-consumption-tips {
  color: darkgrey;
  font-size: 12px;
}
.preferential-conditions-list-item-select-text {
  color: #F8B009;
  font-size: 13px;
}
.preferential-conditions-add {
  display: block;
  margin-left: 90px;
  height: 35px;
  color: #F8B009;
  padding: 5px 0 0 0;
}
.ivu-form-item {
  margin-bottom: 15px;
}
</style>
